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 with_opts=chroot.with_opts, without_opts=chroot.without_opts) 33 # FIXME - test if chroot belongs to copr 34 if flask.g.user.can_build_in(copr): 35 return render_template("coprs/detail/edit_chroot.html", 36 form=form, copr=copr, chroot=chroot) 37 else: 38 raise AccessRestricted( 39 "You are not allowed to modify chroots in project {0}." 40 .format(copr.name))
41
42 43 @coprs_ns.route("/<username>/<coprname>/update_chroot/<chrootname>/", methods=["POST"]) 44 @coprs_ns.route("/g/<group_name>/<coprname>/update_chroot/<chrootname>/", methods=["POST"]) 45 @login_required 46 @req_with_copr 47 -def chroot_update(copr, chrootname):
48 return process_chroot_update(copr, chrootname)
49
50 51 -def process_chroot_update(copr, chroot_name):
52 53 form = forms.ChrootForm() 54 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 55 56 if not flask.g.user.can_build_in(copr): 57 raise AccessRestricted( 58 "You are not allowed to modify chroots in project {0}." 59 .format(copr.name)) 60 61 if form.validate_on_submit(): 62 if "submit" in flask.request.form: 63 action = flask.request.form["submit"] 64 if action == "update": 65 comps_name = comps_xml = None 66 module_md_name = module_md = 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 if form.module_md.has_file(): 73 module_md = form.module_md.data.stream.read() 74 module_md_name = form.module_md.data.filename 75 76 coprs_logic.CoprChrootsLogic.update_chroot( 77 flask.g.user, chroot, 78 form.buildroot_pkgs.data, 79 form.repos.data, 80 comps=comps_xml, comps_name=comps_name, 81 module_md=module_md, module_md_name=module_md_name, 82 with_opts=form.with_opts.data, without_opts=form.without_opts.data 83 ) 84 85 elif action == "delete_comps": 86 CoprChrootsLogic.remove_comps(flask.g.user, chroot) 87 88 elif action == "delete_module_md": 89 CoprChrootsLogic.remove_module_md(flask.g.user, chroot) 90 91 flask.flash( 92 "Buildroot {0} in project {1} has been updated successfully.".format( 93 chroot_name, copr.name), 'success') 94 95 db.session.commit() 96 return flask.redirect(url_for_copr_edit(copr)) 97 98 else: 99 flask.flash(form.errors, "error") 100 return render_chroot_edit(copr, chroot_name)
101
102 103 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/comps/") 104 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/comps/") 105 @req_with_copr 106 -def chroot_view_comps(copr, chrootname):
107 return render_chroot_view_comps(copr, chrootname)
108
109 110 -def render_chroot_view_comps(copr, chroot_name):
111 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 112 return Response(chroot.comps or "", mimetype="text/plain; charset=utf-8")
113
114 115 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/module_md/") 116 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/module_md/") 117 @req_with_copr 118 -def chroot_view_module_md(copr, chrootname):
119 return render_chroot_view_module_md(copr, chrootname)
120
121 122 -def render_chroot_view_module_md(copr, chroot_name):
123 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 124 return Response(chroot.module_md or "", mimetype="text/plain; charset=utf-8")
125