diff --git a/NEWS b/NEWS index 6fbfe444..c2aaa45d 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ - 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) +- new jobhistory/buildhistory output format (CSV) 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 0521a233..91e2a2ea 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2167,6 +2167,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. + @cmdln.option('', '--csv', action='store_true', + help='generate output in CSV (separated by |)') @cmdln.alias('buildhist') def do_buildhistory(self, subcmd, opts, platform, arch): """${cmd_name}: Shows the build history of a package @@ -2183,8 +2185,14 @@ Please submit there instead, or use --nodevelproject to force direct submission. project = store_read_project(wd) apiurl = store_read_apiurl(wd) - print '\n'.join(get_buildhistory(apiurl, project, package, platform, arch)) + format = 'text' + if opts.csv: + format = 'csv' + print '\n'.join(get_buildhistory(apiurl, project, package, platform, arch, format)) + + @cmdln.option('', '--csv', action='store_true', + help='generate output in CSV (separated by |)') @cmdln.alias('jobhist') def do_jobhistory(self, subcmd, opts, platform, arch): """${cmd_name}: Shows the job history of a project @@ -2205,7 +2213,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. pass apiurl = store_read_apiurl(wd) - print_jobhistory(apiurl, project, package, platform, arch) + format = 'text' + if opts.csv: + format = 'csv' + + print_jobhistory(apiurl, project, package, platform, arch, format) @cmdln.option('-r', '--revision', metavar='rev', diff --git a/osc/core.py b/osc/core.py index 3c1c55c0..dff25e49 100755 --- a/osc/core.py +++ b/osc/core.py @@ -2908,7 +2908,7 @@ def get_buildconfig(apiurl, prj, package, platform, arch): return f.read() -def get_buildhistory(apiurl, prj, package, platform, arch): +def get_buildhistory(apiurl, prj, package, platform, arch, format = 'text'): import time u = makeurl(apiurl, ['build', prj, platform, arch, package, '_history']) f = http_GET(u) @@ -2923,13 +2923,17 @@ def get_buildhistory(apiurl, prj, package, platform, arch): t = time.localtime(int(node.get('time'))) t = time.strftime('%Y-%m-%d %H:%M:%S', t) - r.append('%s %s %6d %s.%d' % (t, srcmd5, rev, versrel, bcnt)) + if format == 'csv': + r.append('%s|%s|%d|%s.%d' % (t, srcmd5, rev, versrel, bcnt)) + else: + r.append('%s %s %6d %s.%d' % (t, srcmd5, rev, versrel, bcnt)) - r.insert(0, 'time srcmd5 rev vers-rel.bcnt') + if format == 'text': + r.insert(0, 'time srcmd5 rev vers-rel.bcnt') return r -def print_jobhistory(apiurl, prj, current_package, platform, arch): +def print_jobhistory(apiurl, prj, current_package, platform, arch, format = 'text'): import time if current_package: u = makeurl(apiurl, ['build', prj, platform, arch, '_jobhistory'], "package=%s" % (current_package)) @@ -2938,7 +2942,8 @@ def print_jobhistory(apiurl, prj, current_package, platform, arch): f = http_GET(u) root = ET.parse(f).getroot() - print "time package reason code build time" + if format == 'text': + print "time package reason code build time" for node in root.findall('jobhist'): package = node.get('package') reason = node.get('reason') @@ -2960,8 +2965,11 @@ def print_jobhistory(apiurl, prj, current_package, platform, arch): waitbuild = "%2dh %2dm %2ds" % (waittm.tm_hour, waittm.tm_min, waittm.tm_sec) else: waitbuild = " %2dm %2ds" % (waittm.tm_min, waittm.tm_sec) - - print '%s %-50s %-16s %-16s %s' % (endtime, package[0:49], reason[0:15], code[0:15], waitbuild) + + if format == 'csv': + print '%s|%s|%s|%s|%s' % (endtime, package, reason, code, waitbuild) + else: + print '%s %-50s %-16s %-16s %s' % (endtime, package[0:49], reason[0:15], code[0:15], waitbuild) def get_commitlog(apiurl, prj, package, revision, format = 'text'):