Skip to content

Commit

Permalink
Make 'meta' command capable of editing attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Jul 19, 2023
1 parent c22aceb commit 81a6565
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,9 @@ 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")

Check warning on line 1820 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L1819-L1820

Added lines #L1819 - L1820 were not covered by tests

apiurl = self.get_api_url()

# Specific arguments
Expand Down Expand Up @@ -1953,6 +1956,16 @@ def do_meta(self, subcmd, opts, *args):
path_args=(project, pattern),
apiurl=apiurl,
template_args=None)
elif cmd == 'attribute':
edit_meta(

Check warning on line 1960 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L1959-L1960

Added lines #L1959 - L1960 were not covered by tests
metatype='attribute',
edit=True,
path_args=(project, 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':
Expand Down
13 changes: 9 additions & 4 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Check warning on line 3942 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3942

Added line #L3942 was not covered by tests

open_mode = 'w'
input_as_str = None
Expand All @@ -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)

Check warning on line 3969 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3968-L3969

Added lines #L3968 - L3969 were not covered by tests
else:
http_PUT(self.url, file=self.filename)

Check warning on line 3971 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L3971

Added line #L3971 was not covered by tests
os.unlink(self.filename)
print('Done.')

Expand Down Expand Up @@ -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'
},
Expand Down Expand Up @@ -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,
):

Expand Down Expand Up @@ -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)

Check warning on line 4158 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L4158

Added line #L4158 was not covered by tests

if edit:
f.edit()
Expand Down

0 comments on commit 81a6565

Please sign in to comment.