diff --git a/NEWS b/NEWS index 7690462c..a9822835 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - "osc cat" now auto-expands through link. + - fixed "osc add" after "osc delete". 0.126 - fix "osc patchinfo" command (crashed before) diff --git a/osc/commandline.py b/osc/commandline.py index 412bb2cb..629e7dec 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -4527,7 +4527,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. @cmdln.option('-r', '--revision', metavar='rev', help='print out the specified revision') @cmdln.option('-e', '--expand', action='store_true', - help='expand linked package') + help='force expand linked package. Use with -n') + @cmdln.option('-n', '--no-auto-expand', action='store_true', + help='expand link only when -e given. Default: try without expansion, then with.') def do_cat(self, subcmd, opts, *args): """${cmd_name}: Output the content of a file to standard output @@ -4562,8 +4564,19 @@ Please submit there instead, or use --nodevelproject to force direct submission. if opts.expand: query['rev'] = show_upstream_srcmd5(conf.config['apiurl'], args[0], args[1], expand=True, revision=opts.revision) u = makeurl(conf.config['apiurl'], ['source', args[0], args[1], args[2]], query=query) - for data in streamfile(u): - sys.stdout.write(data) + try: + for data in streamfile(u): + sys.stdout.write(data) + except urllib2.HTTPError, e: + if e.code == 404 and not opts.expand and not opts.no_auto_expand: + print >>sys.stderr, 'expanding link...' + query['rev'] = show_upstream_srcmd5(conf.config['apiurl'], args[0], args[1], expand=True, revision=opts.revision) + u = makeurl(conf.config['apiurl'], ['source', args[0], args[1], args[2]], query=query) + for data in streamfile(u): + sys.stdout.write(data) + else: + e.osc_msg = 'If linked, try: cat -e' + raise e # helper function to download a file from a specific revision