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