1 import flask
2 from . import query_params, get_copr, file_upload, GET, PUT
3 from .json2form import get_form_compatible_data
4 from coprs.helpers import generate_additional_repos, generate_build_config
5 from coprs.views.misc import api_login_required
6 from coprs.views.apiv3_ns import apiv3_ns
7 from coprs.logic.complex_logic import ComplexLogic
8 from coprs.exceptions import ObjectNotFound, BadRequest
9 from coprs import db, forms
10 from coprs.logic.coprs_logic import CoprChrootsLogic
24
38
41 replace = {
42 "additional_repos": "repos",
43 "additional_packages": "buildroot_pkgs",
44 }
45 output = input.copy()
46 for from_name, to_name in replace.items():
47 if from_name not in output:
48 continue
49 output[to_name] = output.pop(from_name)
50 return output
51
54 return (value or "").split()
55
56
57 @apiv3_ns.route("/project-chroot", methods=GET)
58 @query_params()
59 -def get_project_chroot(ownername, projectname, chrootname):
63
64
65 @apiv3_ns.route("/project-chroot/build-config", methods=GET)
66 @query_params()
67 -def get_build_config(ownername, projectname, chrootname):
74
75
76 @apiv3_ns.route("/project-chroot/edit/<ownername>/<projectname>/<chrootname>", methods=PUT)
77 @file_upload()
78 @api_login_required
79 -def edit_project_chroot(ownername, projectname, chrootname):
80 copr = get_copr(ownername, projectname)
81 data = rename_fields(get_form_compatible_data())
82 form = forms.ModifyChrootForm(data, meta={'csrf': False})
83 chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
84
85 if not form.validate_on_submit():
86 raise BadRequest(form.errors)
87
88 buildroot_pkgs = repos = comps_xml = comps_name = with_opts = without_opts = None
89 if "buildroot_pkgs" in data:
90 buildroot_pkgs = form.buildroot_pkgs.data
91 if "repos" in data:
92 repos = form.repos.data
93 if "with_opts" in data:
94 with_opts = form.with_opts.data
95 if "without_opts" in data:
96 without_opts = form.without_opts.data
97 if form.upload_comps.has_file():
98 comps_xml = form.upload_comps.data.stream.read()
99 comps_name = form.upload_comps.data.filename
100 if form.delete_comps.data:
101 CoprChrootsLogic.remove_comps(flask.g.user, chroot)
102 CoprChrootsLogic.update_chroot(
103 flask.g.user, chroot, buildroot_pkgs, repos, comps=comps_xml, comps_name=comps_name,
104 with_opts=with_opts, without_opts=without_opts)
105 db.session.commit()
106 return flask.jsonify(to_dict(chroot))
107