From 95998ef80d623ef95616a23a685a04971039812a Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 18 Jul 2023 13:13:35 +0200 Subject: [PATCH] Make 'meta' command capable of editing attributes --- osc/commandline.py | 19 +++++++++++++++++++ osc/core.py | 13 +++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 9ec6a08841..9f66ec612a 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1816,7 +1816,16 @@ def do_meta(self, subcmd, opts, *args): if opts.add and opts.set: self.argparse_error("Options --add and --set are mutually exclusive") + if cmd == "attribute" and opts.edit and not opts.attribute: + self.argparse_error("Please specify --attribute") + apiurl = self.get_api_url() + project = None + package = None + subpackage = None + user = None + group = None + pattern = None # Specific arguments # @@ -1953,6 +1962,16 @@ def do_meta(self, subcmd, opts, *args): path_args=(project, pattern), apiurl=apiurl, template_args=None) + elif cmd == 'attribute': + edit_meta( + metatype='attribute', + edit=True, + path_args=(quote_plus(project), quote_plus(opts.attribute)), + apiurl=apiurl, + # PUT is not supported + method="POST", + template_args=None, + ) # create attribute entry if (opts.create or opts.set or opts.add) and cmd == 'attribute': diff --git a/osc/core.py b/osc/core.py index 4ecf96f4cc..fa6af0e043 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3929,7 +3929,7 @@ def is_force_supported(self): def __call__(self, **kwargs): return self._delegate(**kwargs) - def __init__(self, url, input, change_is_required=False, file_ext='.xml'): + def __init__(self, url, input, change_is_required=False, file_ext='.xml', method=None): if isinstance(url, self._URLFactory): self._url_factory = url else: @@ -3939,6 +3939,7 @@ def __init__(self, url, input, change_is_required=False, file_ext='.xml'): self.url = self._url_factory() self.change_is_required = change_is_required (fd, self.filename) = tempfile.mkstemp(prefix='osc_metafile.', suffix=file_ext) + self._method = method open_mode = 'w' input_as_str = None @@ -3964,7 +3965,10 @@ def sync(self): print('Sending meta data...') # don't do any exception handling... it's up to the caller what to do in case # of an exception - http_PUT(self.url, file=self.filename) + if self._method == "POST": + http_POST(self.url, file=self.filename) + else: + http_PUT(self.url, file=self.filename) os.unlink(self.filename) print('Done.') @@ -4021,7 +4025,7 @@ def discard(self): 'template': new_package_templ, 'file_ext': '.xml' }, - 'attribute': {'path': 'source/%s/%s/_meta', + 'attribute': {'path': 'source/%s/_attribute/%s', 'template': new_attribute_templ, 'file_ext': '.xml' }, @@ -4117,6 +4121,7 @@ def edit_meta( remove_linking_repositories=False, change_is_required=False, apiurl: Optional[str] = None, + method: Optional[str] = None, msg=None, ): @@ -4150,7 +4155,7 @@ def delegate(force=force): return make_meta_url(metatype, path_args, apiurl, force, remove_linking_repositories, msg) url_factory = metafile._URLFactory(delegate) - f = metafile(url_factory, data, change_is_required, metatypes[metatype]['file_ext']) + f = metafile(url_factory, data, change_is_required, metatypes[metatype]['file_ext'], method=method) if edit: f.edit()