import sys
from xml.etree.ElementTree import iterparse, dump
author = sys.argv[1]
iparse = iterparse(sys.stdin, ['start', 'end'])
for event, elem in iparse:
if event == 'start' and elem.tag == 'log':
logNode = elem
break
logentries = (elem for event, elem in iparse
if event == 'end' and elem.tag == 'logentry')
for logentry in logentries:
if logentry.find('author').text == author:
dump(logentry)
logNode.remove(logentry)
如果你把上面的 svnlogstripbyauthor.py 保存起来,你可以称之为:
svn log --xml other-options | svnLogStripByAuthor.py user
#!/usr/bin/python
# coding:utf-8
import sys
argv_len = len(sys.argv)
def help():
print 'Filter svnlog by user or date! '
print 'USEAGE: svnlog [ARGs] '
print 'ARGs: '
print ' -n[=name]: '
print ' filter by the special [=name]\n'
print ' -t[=date]: '
print ' filter by the special [=date] '
print 'EXP: '
print '1. Filter ruikye\'s commit log \n'
print ' svn log -l 50 | svnlog -n=ruikye\n'
if not argv_len - 1:
help()
quit()
author = ''
date = ''
for index in range(1, argv_len):
argv = sys.argv[index]
if argv.startswith('-n='):
author = argv.replace('-n=', '')
elif argv.startswith('-t='):
date = argv.replace('-t=', '')
else:
help()
quit()
if author == '' and date == '':
help()
quit()
SPLIT_LINE =
'------------------------------------------------------------------------'
src = ''.join(sys.stdin.readlines()).replace('\n\n', '\n')
lines = src.split(SPLIT_LINE)
for line in lines:
if author in line and date in line:
print SPLIT_LINE, line
if len(lines):
print SPLIT_LINE