mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-26 06:46:13 +01:00
new log/rlog output formats (CSV and XML)
This commit is contained in:
parent
6552c00928
commit
63590a80be
1
NEWS
1
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
|
||||
|
@ -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',
|
||||
|
31
osc/core.py
31
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('<?xml version="1.0"?>')
|
||||
r.append('<log>')
|
||||
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('<logentry')
|
||||
r.append(' revision="%s">' % rev)
|
||||
r.append('<author>%s</author>' % user)
|
||||
r.append('<date>%s</date>' % t)
|
||||
r.append('<msg>%s</msg>' %
|
||||
comment.replace('&', '&').replace('<', '>').replace('>', '<'))
|
||||
r.append('</logentry>')
|
||||
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('</log>')
|
||||
return r
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user