mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-23 05:26:16 +01:00
- do_setlinkrev, set_link_rev: fixed #72
Also refactored set_link_rev code a bit so that the new _set_link_rev function could be used by link_pac in the future.
This commit is contained in:
parent
570e3e5c85
commit
8b058b3a47
@ -2390,7 +2390,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
@cmdln.option('-r', '--revision', metavar='rev',
|
@cmdln.option('-r', '--revision', metavar='rev',
|
||||||
help='use the specified revision.')
|
help='use the specified revision.')
|
||||||
@cmdln.option('-R', '--use-plain-revision', action='store_true',
|
@cmdln.option('-R', '--use-plain-revision', action='store_true',
|
||||||
help='Don\'t expand revsion based on baserev, the revision which was used when commit happened.')
|
help='Do not expand revision the specified or latest rev')
|
||||||
@cmdln.option('-u', '--unset', action='store_true',
|
@cmdln.option('-u', '--unset', action='store_true',
|
||||||
help='remove revision in link, it will point always to latest revision')
|
help='remove revision in link, it will point always to latest revision')
|
||||||
def do_setlinkrev(self, subcmd, opts, *args):
|
def do_setlinkrev(self, subcmd, opts, *args):
|
||||||
@ -2408,12 +2408,6 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
args = slash_split(args)
|
args = slash_split(args)
|
||||||
apiurl = self.get_api_url()
|
apiurl = self.get_api_url()
|
||||||
package = None
|
package = None
|
||||||
expand = True
|
|
||||||
baserev = True
|
|
||||||
if opts.use_plain_revision:
|
|
||||||
expand = False
|
|
||||||
baserev = False
|
|
||||||
|
|
||||||
rev = parseRevisionOption(opts.revision)[0] or ''
|
rev = parseRevisionOption(opts.revision)[0] or ''
|
||||||
if opts.unset:
|
if opts.unset:
|
||||||
rev = None
|
rev = None
|
||||||
@ -2440,7 +2434,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
packages = meta_get_packagelist(apiurl, project)
|
packages = meta_get_packagelist(apiurl, project)
|
||||||
|
|
||||||
for p in packages:
|
for p in packages:
|
||||||
rev = set_link_rev(apiurl, project, p, revision=rev, expand=expand, baserev=baserev)
|
rev = set_link_rev(apiurl, project, p, revision=rev,
|
||||||
|
expand=not opts.use_plain_revision)
|
||||||
if rev is None:
|
if rev is None:
|
||||||
print('removed revision from link')
|
print('removed revision from link')
|
||||||
else:
|
else:
|
||||||
@ -2585,7 +2580,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
opts.cicount = "copy"
|
opts.cicount = "copy"
|
||||||
|
|
||||||
if opts.current and not opts.new_package:
|
if opts.current and not opts.new_package:
|
||||||
rev, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, expand=1)
|
rev, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, expand=True)
|
||||||
if rev == None or len(rev) < 32:
|
if rev == None or len(rev) < 32:
|
||||||
# vrev is only needed for srcmd5 and OBS instances < 2.1.17 do not support it
|
# vrev is only needed for srcmd5 and OBS instances < 2.1.17 do not support it
|
||||||
vrev = None
|
vrev = None
|
||||||
|
42
osc/core.py
42
osc/core.py
@ -3485,8 +3485,8 @@ def show_upstream_xsrcmd5(apiurl, prj, pac, revision=None, linkrev=None, linkrep
|
|||||||
return li.xsrcmd5
|
return li.xsrcmd5
|
||||||
|
|
||||||
|
|
||||||
def show_upstream_rev_vrev(apiurl, prj, pac, revision=None, expand=False, linkrev=None, meta=False):
|
def show_upstream_rev_vrev(apiurl, prj, pac, revision=None, expand=False, meta=False):
|
||||||
m = show_files_meta(apiurl, prj, pac, revision=revision, expand=expand, linkrev=linkrev, meta=meta)
|
m = show_files_meta(apiurl, prj, pac, revision=revision, expand=expand, meta=meta)
|
||||||
et = ET.fromstring(''.join(m))
|
et = ET.fromstring(''.join(m))
|
||||||
return et.get('rev'), et.get('vrev')
|
return et.get('rev'), et.get('vrev')
|
||||||
|
|
||||||
@ -5953,12 +5953,7 @@ def owner(apiurl, binary, mode="binary", attribute=None, project=None, usefilter
|
|||||||
pass
|
pass
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def set_link_rev(apiurl, project, package, revision='', expand=False, baserev=False):
|
def set_link_rev(apiurl, project, package, revision='', expand=False):
|
||||||
"""
|
|
||||||
updates the rev attribute of the _link xml. If revision is set to None
|
|
||||||
the rev attribute is removed from the _link xml. If revision is set to ''
|
|
||||||
the "plain" upstream revision is used (if xsrcmd5 and baserev aren't specified).
|
|
||||||
"""
|
|
||||||
url = makeurl(apiurl, ['source', project, package, '_link'])
|
url = makeurl(apiurl, ['source', project, package, '_link'])
|
||||||
try:
|
try:
|
||||||
f = http_GET(url)
|
f = http_GET(url)
|
||||||
@ -5966,29 +5961,38 @@ def set_link_rev(apiurl, project, package, revision='', expand=False, baserev=Fa
|
|||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project)
|
e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project)
|
||||||
raise
|
raise
|
||||||
|
revision = _set_link_rev(apiurl, project, package, root, revision, expand=expand)
|
||||||
|
l = ET.tostring(root, encoding=ET_ENCODING)
|
||||||
|
http_PUT(url, data=l)
|
||||||
|
|
||||||
# set revision element
|
def _set_link_rev(apiurl, project, package, root, revision='', expand=False):
|
||||||
|
"""
|
||||||
|
Updates the rev attribute of the _link xml. If revision is set to None
|
||||||
|
the rev and vrev attributes are removed from the _link xml.
|
||||||
|
updates the rev attribute of the _link xml. If revision is the empty
|
||||||
|
string the latest rev of the link's source package is used (or the
|
||||||
|
xsrcmd5 if expand is True). If revision is neither None nor the empty
|
||||||
|
string the _link's rev attribute is set to this revision (or to the
|
||||||
|
xsrcmd5 if expand is True).
|
||||||
|
"""
|
||||||
src_project = root.get('project', project)
|
src_project = root.get('project', project)
|
||||||
src_package = root.get('package', package)
|
src_package = root.get('package', package)
|
||||||
linkrev = None
|
|
||||||
vrev = None
|
vrev = None
|
||||||
if baserev:
|
if revision == '':
|
||||||
linkrev = 'base'
|
revision = root.get('rev', '')
|
||||||
expand = True
|
|
||||||
if revision is None:
|
if revision is None:
|
||||||
if 'rev' in root.keys():
|
if 'rev' in root.keys():
|
||||||
del root.attrib['rev']
|
del root.attrib['rev']
|
||||||
elif revision == '' or expand:
|
if 'vrev' in root.keys():
|
||||||
revision, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, revision=revision, linkrev=linkrev, expand=expand)
|
del root.attrib['vrev']
|
||||||
|
elif not revision or expand:
|
||||||
|
revision, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, revision=revision, expand=expand)
|
||||||
|
|
||||||
if revision:
|
if revision:
|
||||||
root.set('rev', revision)
|
root.set('rev', revision)
|
||||||
# add vrev when revision is a srcmd5
|
# add vrev when revision is a srcmd5
|
||||||
if vrev and revision and len(revision) >= 32:
|
if vrev is not None and revision is not None and len(revision) >= 32:
|
||||||
root.set('vrev', vrev)
|
root.set('vrev', vrev)
|
||||||
|
|
||||||
l = ET.tostring(root, encoding=ET_ENCODING)
|
|
||||||
http_PUT(url, data=l)
|
|
||||||
return revision
|
return revision
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user