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):
30
33 """
34 Using a pre-filled form, copr and chroot instances, render the
35 edit_chroot.html template.
36 """
37
38 if flask.g.user.can_build_in(copr):
39 return render_template("coprs/detail/edit_chroot.html",
40 form=form, copr=copr, chroot=chroot)
41 raise AccessRestricted(
42 "You are not allowed to modify chroots in project {0}."
43 .format(copr.name))
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):
51 chroot_name = chrootname
52 form = forms.ChrootForm()
53 chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)
54
55 if not flask.g.user.can_build_in(copr):
56 raise AccessRestricted(
57 "You are not allowed to modify chroots in project {0}."
58 .format(copr.name))
59
60 if not form.validate_on_submit():
61 flask.flash(form.errors, "error")
62 return render_chroot_edit(form, copr, chroot)
63
64 if "submit" in flask.request.form:
65 action = flask.request.form["submit"]
66 if action == "update":
67 comps_name = comps_xml = None
68
69 if form.comps.has_file():
70 comps_xml = form.comps.data.stream.read()
71 comps_name = form.comps.data.filename
72
73 coprs_logic.CoprChrootsLogic.update_chroot(
74 flask.g.user, chroot,
75 form.buildroot_pkgs.data,
76 form.repos.data,
77 comps=comps_xml, comps_name=comps_name,
78 with_opts=form.with_opts.data, without_opts=form.without_opts.data,
79 module_toggle=form.module_toggle.data,
80 bootstrap=form.bootstrap.data,
81 bootstrap_image=form.bootstrap_image.data,
82 )
83
84 elif action == "delete_comps":
85 CoprChrootsLogic.remove_comps(flask.g.user, chroot)
86
87 flask.flash(
88 "Buildroot {0} in project {1} has been updated successfully.".format(
89 chroot_name, copr.name), 'success')
90
91 db.session.commit()
92 return flask.redirect(url_for_copr_edit(copr))
93
94
95 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/comps/")
96 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/comps/")
97 @req_with_copr
98 -def chroot_view_comps(copr, chrootname):
100
105