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):
23
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):
50
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):
101
106