1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-27 02:16:12 +01:00

Merge pull request #622 from jberry-suse/parseRevisionOption-clean

osc/core: parseRevisionOption(): cleanup and make logic consistent.
This commit is contained in:
Daniel Mach 2022-04-04 10:52:37 +02:00 committed by GitHub
commit 5d6cfe80d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 20 deletions

View File

@ -7048,7 +7048,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
project = args[0] project = args[0]
package = args[1] package = args[1]
rev, rev_upper = parseRevisionOption(opts.revision) rev, rev_upper = parseRevisionOption(opts.revision, allow_md5=False)
if rev and not checkRevision(project, package, rev, apiurl, opts.meta): if rev and not checkRevision(project, package, rev, apiurl, opts.meta):
print('Revision \'%s\' does not exist' % rev, file=sys.stderr) print('Revision \'%s\' does not exist' % rev, file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -6699,32 +6699,22 @@ def cmdbuild(apiurl, cmd, project, package=None, arch=None, repo=None, code=None
return root.get('code') return root.get('code')
def parseRevisionOption(string): def parseRevisionOption(string, allow_md5=True):
""" """
returns a tuple which contains the revisions returns a tuple which contains the revisions
""" """
revisions = [None, None]
if string: if string:
if ':' in string: parts = string.split(':')
splitted_rev = string.split(':') for i, revision in enumerate(parts[0:2], 0):
try: if revision.isdigit() or (allow_md5 and revision.isalnum() and len(revision) == 32):
for i in splitted_rev: revisions[i] = revision
int(i) elif revision != '' and revision != 'latest':
return splitted_rev
except ValueError:
print('your revision \'%s\' will be ignored' % string, file=sys.stderr) print('your revision \'%s\' will be ignored' % string, file=sys.stderr)
return None, None return None, None
else:
if string.isdigit(): return tuple(revisions)
return string, None
elif string.isalnum() and len(string) == 32:
# could be an md5sum
return string, None
else:
print('your revision \'%s\' will be ignored' % string, file=sys.stderr)
return None, None
else:
return None, None
def checkRevision(prj, pac, revision, apiurl=None, meta=False): def checkRevision(prj, pac, revision, apiurl=None, meta=False):
""" """