From 69e3fd1d4e6b2ae5ec3469808001bcf7a4a45ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20H=C3=BCwe?= Date: Fri, 2 Nov 2007 18:18:30 +0000 Subject: [PATCH] - added new "cat" command to print a file on the standard output --- osc/commandline.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/osc/commandline.py b/osc/commandline.py index c4ddad05..a71116e2 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1940,7 +1940,40 @@ class Osc(cmdln.Cmdln): print ', '.join(maintainers) + def do_cat(self, subcmd, opts, *args): + """${cmd_name}: print file on the standard output + Examples: + osc cat project package file + osc cat project/package/file + + ${cmd_usage} + ${cmd_option_list} + """ + + args = slash_split(args) + if len(args) != 3: + print >>sys.stderr, 'error - incorrect number of arguments' + sys.exit(1) + import tempfile + (fd, filename) = tempfile.mkstemp(prefix = 'osc_%s.' % args[2], dir = '/tmp') + get_source_file(conf.config['apiurl'], args[0], args[1], args[2], targetfilename=filename) + if binary(os.read(fd, 4098)): + print >>sys.stderr, 'error - cannot display binary file \'%s\'' % args[2] + else: + print '### Beginning of file: \'%s\' ###' % filename + while True: + buf = os.read(fd, BUFSIZE) + if not buf: + break + else: + print buf + print '### End of file ###' + try: + os.close(fd) + os.unlink(filename) + except: + pass # fini! ###############################################################################