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 @login_required 22 @req_with_copr 23 -def chroot_edit(copr, chrootname):
24 return render_chroot_edit(copr, chrootname)
25
26 27 @coprs_ns.route("/g/<group_name>/<coprname>/edit_chroot/<chrootname>/") 28 @login_required 29 @req_with_copr 30 -def group_chroot_edit(copr, chrootname):
31 return render_chroot_edit(copr, chrootname)
32
33 34 -def render_chroot_edit(copr, chroot_name):
35 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 36 37 # todo: get COPR_chroot, not mock chroot, WTF?! 38 # form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot)) 39 40 form = forms.ChrootForm(buildroot_pkgs=chroot.buildroot_pkgs) 41 # FIXME - test if chroot belongs to copr 42 if flask.g.user.can_build_in(copr): 43 return render_template("coprs/detail/edit_chroot.html", 44 form=form, copr=copr, chroot=chroot) 45 else: 46 raise AccessRestricted( 47 "You are not allowed to modify chroots in project {0}." 48 .format(copr.name))
49 50 51 @coprs_ns.route("/<username>/<coprname>/update_chroot/<chrootname>/", 52 methods=["POST"])
53 @login_required 54 @req_with_copr 55 -def chroot_update(copr, chrootname):
56 return process_chroot_update(copr, chrootname)
57 58 59 @coprs_ns.route("/g/<group_name>/<coprname>/update_chroot/<chrootname>/", 60 methods=["POST"])
61 @login_required 62 @req_with_copr 63 -def group_chroot_update(copr, chrootname):
64 return process_chroot_update(copr, chrootname)
65
66 67 -def process_chroot_update(copr, chroot_name):
68 69 form = forms.ChrootForm() 70 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 71 72 if not flask.g.user.can_build_in(copr): 73 raise AccessRestricted( 74 "You are not allowed to modify chroots in project {0}." 75 .format(copr.name)) 76 77 if form.validate_on_submit(): 78 if "submit" in flask.request.form: 79 action = flask.request.form["submit"] 80 if action == "update": 81 comps_name = comps_xml = None 82 module_md_name = module_md = None 83 84 if form.comps.has_file(): 85 comps_xml = form.comps.data.stream.read() 86 comps_name = form.comps.data.filename 87 88 if form.module_md.has_file(): 89 module_md = form.module_md.data.stream.read() 90 module_md_name = form.module_md.data.filename 91 92 coprs_logic.CoprChrootsLogic.update_chroot( 93 flask.g.user, chroot, form.buildroot_pkgs.data, 94 comps=comps_xml, comps_name=comps_name, 95 module_md=module_md, module_md_name=module_md_name 96 ) 97 98 elif action == "delete_comps": 99 CoprChrootsLogic.remove_comps(flask.g.user, chroot) 100 101 elif action == "delete_module_md": 102 CoprChrootsLogic.remove_module_md(flask.g.user, chroot) 103 104 flask.flash( 105 "Buildroot {0} in project {1} has been updated successfully.".format( 106 chroot_name, copr.name)) 107 108 db.session.commit() 109 return flask.redirect(url_for_copr_edit(copr)) 110 111 else: 112 flask.flash("You are not allowed to modify chroots.") 113 return render_chroot_edit(copr, chroot_name)
114
115 116 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/comps/") 117 @req_with_copr 118 -def chroot_view_comps(copr, chrootname):
119 return render_chroot_view_comps(copr, chrootname)
120
121 122 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/comps/") 123 @req_with_copr 124 -def group_chroot_view_comps(copr, chrootname):
125 return render_chroot_view_comps(copr, chrootname)
126
127 128 -def render_chroot_view_comps(copr, chroot_name):
129 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 130 return Response(chroot.comps or "", mimetype="text/plain; charset=utf-8")
131
132 133 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/module_md/") 134 @req_with_copr 135 -def chroot_view_module_md(copr, chrootname):
136 return render_chroot_view_module_md(copr, chrootname)
137
138 139 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/module_md/") 140 @req_with_copr 141 -def group_chroot_view_module_md(copr, chrootname):
142 return render_chroot_view_module_md(copr, chrootname)
143
144 145 -def render_chroot_view_module_md(copr, chroot_name):
146 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) 147 return Response(chroot.module_md or "", mimetype="text/plain; charset=utf-8")
148