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):
26
44
45
46 @coprs_ns.route("/<username>/<coprname>/update_chroot/<chrootname>/", methods=["POST"])
47 @coprs_ns.route("/g/<group_name>/<coprname>/update_chroot/<chrootname>/", methods=["POST"])
48 @login_required
49 @req_with_copr
50 -def chroot_update(copr, chrootname):
52
55
56 form = forms.ChrootForm()
57 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)
58
59 if not flask.g.user.can_build_in(copr):
60 raise AccessRestricted(
61 "You are not allowed to modify chroots in project {0}."
62 .format(copr.name))
63
64 if form.validate_on_submit():
65 if "submit" in flask.request.form:
66 action = flask.request.form["submit"]
67 if action == "update":
68 comps_name = comps_xml = None
69 module_md_name = module_md = None
70
71 if form.comps.has_file():
72 comps_xml = form.comps.data.stream.read()
73 comps_name = form.comps.data.filename
74
75 if form.module_md.has_file():
76 module_md = form.module_md.data.stream.read()
77 module_md_name = form.module_md.data.filename
78
79 coprs_logic.CoprChrootsLogic.update_chroot(
80 flask.g.user, chroot,
81 form.buildroot_pkgs.data,
82 form.repos.data,
83 comps=comps_xml, comps_name=comps_name,
84 module_md=module_md, module_md_name=module_md_name,
85 with_opts=form.with_opts.data, without_opts=form.without_opts.data
86 )
87
88 elif action == "delete_comps":
89 CoprChrootsLogic.remove_comps(flask.g.user, chroot)
90
91 elif action == "delete_module_md":
92 CoprChrootsLogic.remove_module_md(flask.g.user, chroot)
93
94 flask.flash(
95 "Buildroot {0} in project {1} has been updated successfully.".format(
96 chroot_name, copr.name), 'success')
97
98 db.session.commit()
99 return flask.redirect(url_for_copr_edit(copr))
100
101 else:
102 flask.flash(form.errors, "error")
103 return render_chroot_edit(copr, chroot_name)
104
105
106 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/comps/")
107 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/comps/")
108 @req_with_copr
109 -def chroot_view_comps(copr, chrootname):
111
116
117
118 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/module_md/")
119 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/module_md/")
120 @req_with_copr
121 -def chroot_view_module_md(copr, chrootname):
123
128