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
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):
49
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):
108
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):
120
125