From d547203c129b038edb9c8ac478f643268ff56909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Thu, 9 Apr 2009 08:21:12 +0000 Subject: [PATCH] - support listings of older revisions with "osc ls -R" - add --current parameter for linkpac to use current revision of source package fixed. - add osc setlinkrev to add or update revision number in links easily - fix streaming of binary files via "cat" (#493325) --- NEWS | 6 +++++ osc/commandline.py | 67 +++++++++++++++++++++++++++++++++++++++++----- osc/core.py | 41 +++++++++++++++++++++++++--- 3 files changed, 104 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index e397f906..2293b875 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +0.116: +- support listings of older revisions with "osc ls -R" +- add --current parameter for linkpac to use current revision of source package fixed. +- add osc setlinkrev to add or update revision number in links easily +- fix streaming of binary files via "cat" (#493325) + 0.115: - optional transfer of devel project during copy_pac and link_pac is fixing opertation with remote build service instance diff --git a/osc/commandline.py b/osc/commandline.py index 4891618b..7292712f 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -142,6 +142,8 @@ class Osc(cmdln.Cmdln): @cmdln.alias('ls') @cmdln.option('-a', '--arch', metavar='ARCH', help='specify architecture') + @cmdln.option('-R', '--revision', metavar='REVISION', + help='specify revision') @cmdln.option('-r', '--repo', metavar='REPO', help='specify repository') @cmdln.option('-b', '--binaries', action='store_true', @@ -198,6 +200,8 @@ class Osc(cmdln.Cmdln): if opts.binaries: if not args: raise oscerr.WrongArgs('There are no binaries to list above project level.') + if opts.revision: + raise oscerr.WrongOptions('Sorry, the --revision option is not supported for binaries.') elif len(args) == 1: #if opts.verbose: @@ -227,7 +231,8 @@ class Osc(cmdln.Cmdln): project, package, verbose=opts.verbose, - expand=opts.expand) + expand=opts.expand, + revision=opts.revision) if opts.verbose: out = [ '%s %7d %9d %s %s' % (i.md5, i.rev, i.size, shorttime(i.mtime), i.name) \ for i in l if not fname or fname == i.name ] @@ -693,6 +698,57 @@ Please submit there instead, or use --nodevelproject to force direct submission. return 2 + @cmdln.option('-r', '--revision', metavar='rev', + help='use the specified revision.') + def do_setlinkrev(self, subcmd, opts, *args): + """${cmd_name}: Updates a revision number in a source link. + + This command adds or updates a specified revision number in a source link. + The current revision of the source is used, if no revision number is specified. + + usage: + osc setlinkrev + osc setlinkrev PROJECT PACKAGE + ${cmd_option_list} + """ + + args = slash_split(args) + + if not args or len(args) == 0: + p = findpacs(os.curdir)[0] + project = p.prjname + package = p.name + if p.islink() and project and package: + src_project = p.linkinfo.project + src_package = p.linkinfo.package + else: + sys.exit('Local directory is no checked out package, aborting') + elif len(args) == 2: + project = args[0] + package = args[1] + else: + raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \ + + self.get_cmd_help('setlinkrev')) + + rev, dummy = parseRevisionOption(opts.revision) + + if not rev: + if not args or len(args) == 0: + revision = show_upstream_rev(conf.config['apiurl'], src_project, src_package); + else: + url = makeurl(conf.config['apiurl'], ['source', project, package, '_link']) + try: + f = http_GET(url) + root = ET.parse(f).getroot() + except urllib2.HTTPError, e: + e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project) + raise + + return set_link_rev(project, package) + + set_link_rev(project, package, rev) + + @cmdln.option('-c', '--current', action='store_true', help='link fixed against current revision.') @cmdln.option('-r', '--revision', metavar='rev', @@ -2653,11 +2709,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. get_source_file(conf.config['apiurl'], args[0], args[1], args[2], targetfilename=filename, revision=rev) - if binary_file(filename): - print >>sys.stderr, 'error - cannot display binary file \'%s\'' % args[2] - else: - for line in open(filename): - print line.rstrip('\n') + # FIXME: stream directly without temp file and without keeping the entire file in memory + f = open(filename, 'rb') + sys.stdout.write(f.read()) + f.close() try: os.unlink(filename) diff --git a/osc/core.py b/osc/core.py index de83d743..dba53d83 100755 --- a/osc/core.py +++ b/osc/core.py @@ -80,8 +80,13 @@ It also does some weird stuff. x86_64 i586 - - + + + x86_64 + i586 + + + x86_64 i586 @@ -1580,7 +1585,7 @@ def meta_get_packagelist(apiurl, prj): return [ node.get('name') for node in root.findall('entry') ] -def meta_get_filelist(apiurl, prj, package, verbose=False, expand=False): +def meta_get_filelist(apiurl, prj, package, verbose=False, expand=False, revision=0): """return a list of file names, or a list File() instances if verbose=True""" @@ -1588,7 +1593,12 @@ def meta_get_filelist(apiurl, prj, package, verbose=False, expand=False): expand = 'expand=1' else: expand = '' - u = makeurl(apiurl, ['source', prj, package], query=expand) + if revision and revision > 0: + revision = '?rev=%s' % revision + else: + revision = '' + + u = makeurl(apiurl, ['source', prj, package, revision], query=expand) f = http_GET(u) root = ET.parse(f).getroot() @@ -3179,12 +3189,35 @@ def search(apiurl, search_list, kind, search_term, verbose = False, exact_matche title = title[:61] + '...' result.append(title) if repos_baseurl: + # FIXME: no hardcoded URL of instance result.append('http://download.opensuse.org/repositories/%s/' % project.replace(':', ':/')) if result: return result else: return None + +def set_link_rev(project, package, revision = 0): + url = makeurl(conf.config['apiurl'], ['source', project, package, '_link']) + try: + f = http_GET(url) + root = ET.parse(f).getroot() + except urllib2.HTTPError, e: + e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project) + raise + + if not revision or revision == 0: + src_project = root.attrib['project'] + src_package = root.attrib['package'] + revision = show_upstream_rev(conf.config['apiurl'], src_project, src_package); + + # set revision element + root.attrib['rev'] = revision + l = ET.tostring(root) + # upload _link file again + http_PUT(url, data=l) + + def delete_dir(dir): # small security checks if os.path.islink(dir):