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):
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):
32
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):
57
58
59 @coprs_ns.route("/g/<group_name>/<coprname>/update_chroot/<chrootname>/",
60 methods=["POST"])
65
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,
94 form.buildroot_pkgs.data,
95 form.repos.data,
96 comps=comps_xml, comps_name=comps_name,
97 module_md=module_md, module_md_name=module_md_name
98 )
99
100 elif action == "delete_comps":
101 CoprChrootsLogic.remove_comps(flask.g.user, chroot)
102
103 elif action == "delete_module_md":
104 CoprChrootsLogic.remove_module_md(flask.g.user, chroot)
105
106 flask.flash(
107 "Buildroot {0} in project {1} has been updated successfully.".format(
108 chroot_name, copr.name))
109
110 db.session.commit()
111 return flask.redirect(url_for_copr_edit(copr))
112
113 else:
114 flask.flash(form.errors, "error")
115 return render_chroot_edit(copr, chroot_name)
116
117
118 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/comps/")
119 @req_with_copr
120 -def chroot_view_comps(copr, chrootname):
122
123
124 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/comps/")
125 @req_with_copr
126 -def group_chroot_view_comps(copr, chrootname):
128
133
134
135 @coprs_ns.route("/<username>/<coprname>/chroot/<chrootname>/module_md/")
136 @req_with_copr
137 -def chroot_view_module_md(copr, chrootname):
139
140
141 @coprs_ns.route("/g/<group_name>/<coprname>/chroot/<chrootname>/module_md/")
142 @req_with_copr
143 -def group_chroot_view_module_md(copr, chrootname):
145
150