mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-09 22:36:14 +01:00
Offer a force ("f") choice in metafile.edit's error handling code path
Offer a force ("f") choice if, for instance, "osc meta prj foobar -e" fails due to a HTTPError in metafile.edit. If the force choice is selected, a new url is constructed by invoking the metafile._URLFactory instance with a "force='1'" argument (this adds a "force=1" to the original url's query string (*)) and the corresponding file is PUTed to the new url. If this PUT fails again and now the "y" choice is selected, the file is PUTed to the original url (*). (*): Stricly speaking, from metafile.edit's POV, the concrete url depends on the passed in metafile._URLFactory instance, though. Note: the metafile._URLFactory class and its is_force_supported method is a gross hack. That's why this class is marked as private (that is, we can remove it at any point in time again without breaking the API/3rd party applications). An alternative to the metafile._URLFactory approach would be manual URL parsing and manual URL construction (adding "force=1" to the query string)... but this is also pretty awkward (if done properly). Fixes: #916 ("for osc meta edit change y/n to y/n/f") Fixes: #942 ("Offer -f when prjmeta change leads to repo_dependency")
This commit is contained in:
parent
ebcf3de6ab
commit
2cb308105a
55
osc/core.py
55
osc/core.py
@ -2162,8 +2162,11 @@ rev: %s
|
||||
url = ET.SubElement(root, 'url')
|
||||
url.text = self.url
|
||||
|
||||
u = makeurl(self.apiurl, ['source', self.prjname, self.name, '_meta'])
|
||||
mf = metafile(u, ET.tostring(root, encoding=ET_ENCODING))
|
||||
delegate = lambda force=False: make_meta_url('pkg',
|
||||
(self.prjname, self.name),
|
||||
self.apiurl, force=force)
|
||||
url_factory = metafile._URLFactory(delegate)
|
||||
mf = metafile(url_factory, ET.tostring(root, encoding=ET_ENCODING))
|
||||
|
||||
if not force:
|
||||
print('*' * 36, 'old', '*' * 36)
|
||||
@ -3674,10 +3677,29 @@ def show_configuration(apiurl):
|
||||
|
||||
class metafile:
|
||||
"""metafile that can be manipulated and is stored back after manipulation."""
|
||||
|
||||
class _URLFactory:
|
||||
# private class which might go away again...
|
||||
def __init__(self, delegate, force_supported=True):
|
||||
self._delegate = delegate
|
||||
self._force_supported = force_supported
|
||||
|
||||
def is_force_supported(self):
|
||||
return self._force_supported
|
||||
|
||||
def __call__(self, **kwargs):
|
||||
return self._delegate(**kwargs)
|
||||
|
||||
def __init__(self, url, input, change_is_required=False, file_ext='.xml'):
|
||||
import tempfile
|
||||
|
||||
self.url = url
|
||||
if isinstance(url, self._URLFactory):
|
||||
self._url_factory = url
|
||||
else:
|
||||
delegate = lambda **kwargs: url
|
||||
# force is not supported for a raw url
|
||||
self._url_factory = self._URLFactory(delegate, False)
|
||||
self.url = self._url_factory()
|
||||
self.change_is_required = change_is_required
|
||||
(fd, self.filename) = tempfile.mkstemp(prefix = 'osc_metafile.', suffix = file_ext)
|
||||
|
||||
@ -3711,8 +3733,11 @@ class metafile:
|
||||
|
||||
def edit(self):
|
||||
try:
|
||||
try_force = False
|
||||
while True:
|
||||
run_editor(self.filename)
|
||||
if not try_force:
|
||||
run_editor(self.filename)
|
||||
try_force = False
|
||||
try:
|
||||
self.sync()
|
||||
break
|
||||
@ -3728,8 +3753,18 @@ class metafile:
|
||||
summary = root.find('summary')
|
||||
if summary is not None:
|
||||
print(summary.text, file=sys.stderr)
|
||||
ri = raw_input('Try again? ([y/N]): ')
|
||||
if ri not in ['y', 'Y']:
|
||||
if self._url_factory.is_force_supported():
|
||||
prompt = 'Try again? ([y/N/f]): '
|
||||
else:
|
||||
prompt = 'Try again? ([y/N): '
|
||||
|
||||
ri = raw_input(prompt)
|
||||
if ri in ('y', 'Y'):
|
||||
self.url = self._url_factory()
|
||||
elif ri in ('f', 'F') and self._url_factory.is_force_supported():
|
||||
self.url = self._url_factory(force='1')
|
||||
try_force = True
|
||||
else:
|
||||
break
|
||||
finally:
|
||||
self.discard()
|
||||
@ -3866,8 +3901,12 @@ def edit_meta(metatype,
|
||||
print(' osc meta pkg %s %s -e' % (unquote(project), package))
|
||||
return
|
||||
|
||||
url = make_meta_url(metatype, path_args, apiurl, force, remove_linking_repositories, msg)
|
||||
f = metafile(url, data, change_is_required, metatypes[metatype]['file_ext'])
|
||||
delegate = lambda force=force: 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'])
|
||||
|
||||
if edit:
|
||||
f.edit()
|
||||
|
Loading…
Reference in New Issue
Block a user