Mercurial > public > mercurial-scm > hg-stable
comparison tests/svnxml.py @ 16512:c58bdecdb800 stable
test-convert-svn-sink: add helper to smooth svn xml output
svnxml.py parses "svn log --xml" output and prints the attributes shared among
all tested svn versions. This fixes the test with svn 1.7.
Tested with svn 1.6.12 and 1.7.4.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Tue, 24 Apr 2012 13:05:38 +0200 |
parents | |
children | 812eb3b7dc43 |
comparison
equal
deleted
inserted
replaced
16511:ecd2fbe68b25 | 16512:c58bdecdb800 |
---|---|
1 # Read the output of a "svn log --xml" command on stdin, parse it and | |
2 # print a subset of attributes common to all svn versions tested by | |
3 # hg. | |
4 import xml.dom.minidom, sys | |
5 | |
6 def xmltext(e): | |
7 return ''.join(c.data for c | |
8 in e.childNodes | |
9 if c.nodeType == c.TEXT_NODE) | |
10 | |
11 def parseentry(entry): | |
12 e = {} | |
13 e['revision'] = entry.getAttribute('revision') | |
14 e['author'] = xmltext(entry.getElementsByTagName('author')[0]) | |
15 e['msg'] = xmltext(entry.getElementsByTagName('msg')[0]) | |
16 e['paths'] = [] | |
17 paths = entry.getElementsByTagName('paths') | |
18 if paths: | |
19 paths = paths[0] | |
20 for p in paths.getElementsByTagName('path'): | |
21 action = p.getAttribute('action') | |
22 path = xmltext(p) | |
23 frompath = p.getAttribute('copyfrom-path') | |
24 fromrev = p.getAttribute('copyfrom-rev') | |
25 e['paths'].append((path, action, frompath, fromrev)) | |
26 return e | |
27 | |
28 def parselog(data): | |
29 entries = [] | |
30 doc = xml.dom.minidom.parseString(data) | |
31 for e in doc.getElementsByTagName('logentry'): | |
32 entries.append(parseentry(e)) | |
33 return entries | |
34 | |
35 def printentries(entries): | |
36 fp = sys.stdout | |
37 for e in entries: | |
38 for k in ('revision', 'author', 'msg'): | |
39 fp.write(('%s: %s\n' % (k, e[k])).encode('utf-8')) | |
40 for path, action, fpath, frev in sorted(e['paths']): | |
41 frominfo = '' | |
42 if frev: | |
43 frominfo = ' (from %s@%s)' % (fpath, frev) | |
44 p = ' %s %s%s\n' % (action, path, frominfo) | |
45 fp.write(p.encode('utf-8')) | |
46 | |
47 if __name__ == '__main__': | |
48 data = sys.stdin.read() | |
49 entries = parselog(data) | |
50 printentries(entries) | |
51 |