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