Package coprs :: Package views :: Package coprs_ns :: Module coprs_chroots
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.coprs_ns.coprs_chroots

  1  from io import BytesIO 
  2  from zlib import compress, decompress 
  3   
  4  import flask 
  5  from flask import Response, url_for, render_template 
  6   
  7  from coprs import db 
  8  from coprs import forms 
  9  from coprs.exceptions import AccessRestricted 
 10   
 11  from coprs.logic import coprs_logic 
 12  from coprs.logic.complex_logic import ComplexLogic 
 13  from coprs.logic.coprs_logic import CoprChrootsLogic 
 14  from coprs.views.coprs_ns.coprs_general import url_for_copr_edit 
 15   
 16  from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr 
 17  from coprs.views.coprs_ns import coprs_ns 
18 19 20 @coprs_ns.route("/<username>/<coprname>/edit_chroot/<chrootname>/") 21 @coprs_ns.route("/g/<group_name>/<coprname>/edit_chroot/<chrootname>/") 22 @login_required 23 @req_with_copr 24 -def chroot_edit(copr, chrootname):
25 return render_chroot_edit(copr, chrootname)
26
27 28 -def render_chroot_edit(copr, chroot_name):
29 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 30 31 # todo: get COPR_chroot, not mock chroot, WTF?! 32 # form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot)) 33 34 form = forms.ChrootForm(buildroot_pkgs=chroot.buildroot_pkgs, repos=chroot.repos) 35 # FIXME - test if chroot belongs to copr 36 if flask.g.user.can_build_in(copr): 37 return render_template("coprs/detail/edit_chroot.html", 38 form=form, copr=copr, chroot=chroot) 39 else: 40 raise AccessRestricted( 41 "You are not allowed to modify chroots in project {0}." 42 .format(copr.name))
43
44 45 @coprs_ns.route("/<username>/<coprname>/update_chroot/<chrootname>/", methods=["POST"]) 46 @coprs_ns.route("/g/<group_name>/<coprname>/update_chroot/<chrootname>/", methods=["POST"]) 47 @login_required 48 @req_with_copr 49 -def chroot_update(copr, chrootname):
50 return process_chroot_update(copr, chrootname)
51
52 53 -def process_chroot_update(copr, chroot_name):
54 55 form = forms.ChrootForm() 56 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 57 58 if not flask.g.user.can_build_in(copr): 59 raise AccessRestricted( 60 "You are not allowed to modify chroots in project {0}." 61 .format(copr.name)) 62 63 if form.validate_on_submit(): 64 if "submit" in flask.request.form: 65 action = flask.request.form["submit"] 66 if action == "update": 67 comps_name = comps_xml = None 68 module_md_name = module_md = None 69 70 if form.comps.has_file(): 71 comps_xml = form.comps.data.stream.read() 72 comps_name = form.comps.data.filename 73 74 if form.module_md.has_file(): 75 module_md = form.module_md.data.stream.read() 76 module_md_name = form.module_md.data.filename 77 78 coprs_logic.CoprChrootsLogic.update_chroot( 79 flask.g.user, chroot, 80 form.buildroot_pkgs.data, 81 form.repos.data, 82 comps=comps_xml, comps_name=comps_name, 83 module_md=module_md, module_md_name=module_md_name 84 ) 85 86 elif action == "delete_comps": 87 CoprChrootsLogic.remove_comps(flask.g.user, chroot) 88 89 elif action == "delete_module_md": 90 CoprChrootsLogic.remove_module_md(flask.g.user, chroot) 91 92 flask.flash( 93 "Buildroot {0} in project {1} has been updated successfully.".format( 94 chroot_name, copr.name)) 95 96 db.session.commit() 97 return flask.redirect(url_for_copr_edit(copr)) 98 99 else: 100 flask.flash(form.errors, "error") 101 return render_chroot_edit(copr, chroot_name)
102
103 104 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/comps/") 105 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/comps/") 106 @req_with_copr 107 -def chroot_view_comps(copr, chrootname):
108 return render_chroot_view_comps(copr, chrootname)
109
110 111 -def render_chroot_view_comps(copr, chroot_name):
112 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 113 return Response(chroot.comps or "", mimetype="text/plain; charset=utf-8")
114
115 116 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/module_md/") 117 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/module_md/") 118 @req_with_copr 119 -def chroot_view_module_md(copr, chrootname):
120 return render_chroot_view_module_md(copr, chrootname)
121
122 123 -def render_chroot_view_module_md(copr, chroot_name):
124 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 125 return Response(chroot.module_md or "", mimetype="text/plain; charset=utf-8")
126