diff --git a/NEWS b/NEWS index 37e4edf4..6fbfe444 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ - osc now includes automatically generated man page - osc can now store credentials in Gnome keyring if it is available - new support for osc linkpac to specify cicount attribute +- new log/rlog output formats (CSV and XML) 0.117: - support checkout of single package via "osc co PACKAGE" when local dir is project diff --git a/osc/commandline.py b/osc/commandline.py index 8248c9f5..0521a233 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2210,6 +2210,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. @cmdln.option('-r', '--revision', metavar='rev', help='show log of the specified revision') + @cmdln.option('', '--csv', action='store_true', + help='generate output in CSV (separated by |)') + @cmdln.option('', '--xml', action='store_true', + help='generate output in XML') def do_log(self, subcmd, opts): """${cmd_name}: Shows the commit log of a package @@ -2226,11 +2230,21 @@ Please submit there instead, or use --nodevelproject to force direct submission. print >>sys.stderr, 'Revision \'%s\' does not exist' % rev sys.exit(1) - print '\n'.join(get_commitlog(apiurl, project, package, rev)) + format = 'text' + if opts.csv: + format = 'csv' + if opts.xml: + format = 'xml' + + print '\n'.join(get_commitlog(apiurl, project, package, rev, format)) @cmdln.option('-r', '--revision', metavar='rev', help='show log of the specified revision') + @cmdln.option('', '--csv', action='store_true', + help='generate output in CSV (separated by |)') + @cmdln.option('', '--xml', action='store_true', + help='generate output in XML') def do_rlog(self, subcmd, opts, prj, pkg): """${cmd_name}: Shows the commit log of a remote package @@ -2244,7 +2258,13 @@ Please submit there instead, or use --nodevelproject to force direct submission. print >>sys.stderr, 'Revision \'%s\' does not exist' % rev sys.exit(1) - print '\n'.join(get_commitlog(apiurl, prj, pkg, rev)) + format = 'text' + if opts.csv: + format = 'csv' + if opts.xml: + format = 'xml' + + print '\n'.join(get_commitlog(apiurl, prj, pkg, rev, format)) @cmdln.option('-f', '--failed', action='store_true', diff --git a/osc/core.py b/osc/core.py index 0dd26657..4917005f 100755 --- a/osc/core.py +++ b/osc/core.py @@ -2964,13 +2964,16 @@ def print_jobhistory(apiurl, prj, current_package, platform, arch): print '%s %-50s %-16s %-16s %s' % (endtime, package[0:49], reason[0:15], code[0:15], waitbuild) -def get_commitlog(apiurl, prj, package, revision): +def get_commitlog(apiurl, prj, package, revision, format = 'text'): import time, locale u = makeurl(apiurl, ['source', prj, package, '_history']) f = http_GET(u) root = ET.parse(f).getroot() r = [] + if format == 'xml': + r.append('') + r.append('') revisions = root.findall('revision') revisions.reverse() for node in revisions: @@ -2996,12 +2999,28 @@ def get_commitlog(apiurl, prj, package, revision): t = time.localtime(int(node.find('time').text)) t = time.strftime('%Y-%m-%d %H:%M:%S', t) - s = '-' * 76 + \ - '\nr%s | %s | %s | %s | %s\n' % (rev, user, t, srcmd5, version) + \ - '\n' + comment - r.append(s) + if format == 'csv': + s = '%s|%s|%s|%s|%s|%s' % (rev, user, t, srcmd5, version, + comment.replace('\\', '\\\\').replace('\n', '\\n').replace('|', '\\|')) + r.append(s) + elif format == 'xml': + r.append('' % rev) + r.append('%s' % user) + r.append('%s' % t) + r.append('%s' % + comment.replace('&', '&').replace('<', '>').replace('>', '<')) + r.append('') + else: + s = '-' * 76 + \ + '\nr%s | %s | %s | %s | %s\n' % (rev, user, t, srcmd5, version) + \ + '\n' + comment + r.append(s) - r.append('-' * 76) + if format not in ['csv', 'xml']: + r.append('-' * 76) + if format == 'xml': + r.append('') return r