diff --git a/osc/commandline.py b/osc/commandline.py index 85f4fc23..a8c0100c 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -4987,6 +4987,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. help='match only when given attribute exists in meta data') @cmdln.option('-v', '--verbose', action='store_true', help='show more information') + @cmdln.option('-V', '--version', action='store_true', + help='show package version, revision, and srcmd5. CAUTION: This is slow and unreliable') @cmdln.option('-i', '--involved', action='store_true', help='show projects/packages where given person (or myself) is involved as bugowner or maintainer') @cmdln.option('-b', '--bugowner', action='store_true', @@ -5125,11 +5127,25 @@ Please submit there instead, or use --nodevelproject to force direct submission. result.append(project) if not package is None: result.append(package) + + if opts.version: + sr = get_source_rev(apiurl,project,package) + v = sr.get('version') + r = sr.get('rev') + s = sr.get('srcmd5') + if not v or v == 'unknown': v = '-' + if not r: r = '-' + if not s: s = '-' + result.append(v) + result.append(r) + result.append(s) + if opts.verbose: title = node.findtext('title').strip() if len(title) > 60: title = title[:61] + '...' result.append(title) + if opts.repos_baseurl: # FIXME: no hardcoded URL of instance result.append('http://download.opensuse.org/repositories/%s/' % project.replace(':', ':/')) @@ -5153,6 +5169,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. headline = [ '# Project', '# Package' ] else: headline = [ '# Project' ] + if opts.version: + headline.append('# Ver') + headline.append('Rev') + headline.append('Srcmd5') if opts.verbose: headline.append('# Title') if opts.repos_baseurl: diff --git a/osc/core.py b/osc/core.py index f02092cf..feb5709e 100644 --- a/osc/core.py +++ b/osc/core.py @@ -4651,6 +4651,33 @@ def get_buildconfig(apiurl, prj, repository): f = http_GET(u) return f.read() + +def get_source_rev(apiurl, project, package, revision=None): + # API supports ?deleted=1&meta=1&rev=4 + # but not rev=current,rev=latest,rev=top, or anything like this. + # CAUTION: We have to loop through all rev and find the highest one, if none given. + + if revision: + url = makeurl(apiurl, ['source', project, package, '_history'], {'rev':revision}) + else: + url = makeurl(apiurl, ['source', project, package, '_history']) + f = http_GET(url) + xml = ET.parse(f) + ent = None + for new in xml.findall('revision'): + # remember the newest one. + if not ent: + ent = new + elif ent.find('time').text < new.find('time').text: + ent = new + if not ent: + return { 'version': None, 'error':'empty revisionlist: no such package?' } + e = {} + for k in ent.keys(): + e[k] = ent.get(k) + for k in list(ent): + e[k.tag] = k.text + return e def get_buildhistory(apiurl, prj, package, repository, arch, format = 'text'): import time