mirror of
https://github.com/openSUSE/osc.git
synced 2025-04-22 14:19:15 +02:00
Merge pull request #1360 from dmach/edit-attribute
Make 'meta' command capable of editing attributes
This commit is contained in:
commit
b36c2101ba
@ -1829,7 +1829,16 @@ class Osc(cmdln.Cmdln):
|
|||||||
if opts.add and opts.set:
|
if opts.add and opts.set:
|
||||||
self.argparse_error("Options --add and --set are mutually exclusive")
|
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()
|
apiurl = self.get_api_url()
|
||||||
|
project = None
|
||||||
|
package = None
|
||||||
|
subpackage = None
|
||||||
|
user = None
|
||||||
|
group = None
|
||||||
|
pattern = None
|
||||||
|
|
||||||
# Specific arguments
|
# Specific arguments
|
||||||
#
|
#
|
||||||
@ -1966,6 +1975,16 @@ class Osc(cmdln.Cmdln):
|
|||||||
path_args=(project, pattern),
|
path_args=(project, pattern),
|
||||||
apiurl=apiurl,
|
apiurl=apiurl,
|
||||||
template_args=None)
|
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
|
# create attribute entry
|
||||||
if (opts.create or opts.set or opts.add) and cmd == 'attribute':
|
if (opts.create or opts.set or opts.add) and cmd == 'attribute':
|
||||||
|
11
osc/core.py
11
osc/core.py
@ -3928,7 +3928,7 @@ class metafile:
|
|||||||
def __call__(self, **kwargs):
|
def __call__(self, **kwargs):
|
||||||
return self._delegate(**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):
|
if isinstance(url, self._URLFactory):
|
||||||
self._url_factory = url
|
self._url_factory = url
|
||||||
else:
|
else:
|
||||||
@ -3938,6 +3938,7 @@ class metafile:
|
|||||||
self.url = self._url_factory()
|
self.url = self._url_factory()
|
||||||
self.change_is_required = change_is_required
|
self.change_is_required = change_is_required
|
||||||
(fd, self.filename) = tempfile.mkstemp(prefix='osc_metafile.', suffix=file_ext)
|
(fd, self.filename) = tempfile.mkstemp(prefix='osc_metafile.', suffix=file_ext)
|
||||||
|
self._method = method
|
||||||
|
|
||||||
open_mode = 'w'
|
open_mode = 'w'
|
||||||
input_as_str = None
|
input_as_str = None
|
||||||
@ -3963,6 +3964,9 @@ class metafile:
|
|||||||
print('Sending meta data...')
|
print('Sending meta data...')
|
||||||
# don't do any exception handling... it's up to the caller what to do in case
|
# don't do any exception handling... it's up to the caller what to do in case
|
||||||
# of an exception
|
# of an exception
|
||||||
|
if self._method == "POST":
|
||||||
|
http_POST(self.url, file=self.filename)
|
||||||
|
else:
|
||||||
http_PUT(self.url, file=self.filename)
|
http_PUT(self.url, file=self.filename)
|
||||||
os.unlink(self.filename)
|
os.unlink(self.filename)
|
||||||
print('Done.')
|
print('Done.')
|
||||||
@ -4020,7 +4024,7 @@ metatypes = {'prj': {'path': 'source/%s/_meta',
|
|||||||
'template': new_package_templ,
|
'template': new_package_templ,
|
||||||
'file_ext': '.xml'
|
'file_ext': '.xml'
|
||||||
},
|
},
|
||||||
'attribute': {'path': 'source/%s/%s/_meta',
|
'attribute': {'path': 'source/%s/_attribute/%s',
|
||||||
'template': new_attribute_templ,
|
'template': new_attribute_templ,
|
||||||
'file_ext': '.xml'
|
'file_ext': '.xml'
|
||||||
},
|
},
|
||||||
@ -4116,6 +4120,7 @@ def edit_meta(
|
|||||||
remove_linking_repositories=False,
|
remove_linking_repositories=False,
|
||||||
change_is_required=False,
|
change_is_required=False,
|
||||||
apiurl: Optional[str] = None,
|
apiurl: Optional[str] = None,
|
||||||
|
method: Optional[str] = None,
|
||||||
msg=None,
|
msg=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
@ -4149,7 +4154,7 @@ def edit_meta(
|
|||||||
return make_meta_url(metatype, path_args, apiurl, force, remove_linking_repositories, msg)
|
return make_meta_url(metatype, path_args, apiurl, force, remove_linking_repositories, msg)
|
||||||
|
|
||||||
url_factory = metafile._URLFactory(delegate)
|
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:
|
if edit:
|
||||||
f.edit()
|
f.edit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user