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