e53feb482b96db2987c7a1f67a967f6d472b934f
[freebsd-maintainer-scripts/.git] / sss
1 #!/usr/bin/env python
2
3 """
4 sss - sbz svn status verbose on one line
5 """
6
7 import os
8 import shlex
9 import subprocess
10 import sys
11 import xml.etree.ElementTree as ET
12
13 """
14 line = Parse output of svn up
15 foreach path in lines
16     xml data = svn log -rHEAD path --xml
17     author, shortmsg, status, path = parse xml data
18     print status, path, shortmsg, status, author
19 """
20
21 x_data = """U    src/bin/dd/args.c
22 U    src/bin/dd/conv.c
23 U    src/bin/dd/dd.c
24 U    src/bin/dd/dd.h
25 U    src/bin/dd/position.c
26 U    src/bin/pkill/pkill.c
27 U    src/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
28 U    src/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
29 U    src/cddl/usr.sbin/zfsd/zfsd_event.cc
30 U    src/contrib/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
31 U    src/contrib/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
32 U    src/contrib/compiler-rt/lib/esan/esan_sideline_linux.cpp
33 U    src/contrib/compiler-rt/lib/profile/InstrProfilingNameVar.c
34 U   src/contrib/compiler-rt
35 U   src/contrib/libc++
36 """
37
38 x_xml_data = """<?xml version="1.0" encoding="UTF-8"?>
39 <log>
40 <logentry
41    revision="322826">
42 <author>kevans</author>
43 <date>2017-08-24T01:23:33.506520Z</date>
44 <msg>bsdgrep: add a primitive literal matcher
45 </msg>
46 </logentry>
47 </log>"""
48
49
50 def valid_line(line):
51     if line.startswith('U ') or \
52        line.startswith('A ') or \
53        line.startswith('D '):
54         return True
55     else:
56         return False
57
58
59 def main():
60     src_path = os.path.expanduser('~/svn/src/')
61     ports_path = os.path.expanduser('~/svn/ports/')
62     svn_path = sys.argv[1] if len(sys.argv) == 2 else src_path
63     out = {}
64     data = subprocess.run(shlex.split('svn up {0}'.format(svn_path)),
65                           stdout=subprocess.PIPE).stdout
66     data = data.decode("utf-8")
67     for line in data.split('\n'):
68         if not valid_line(line):
69             continue
70         status, path = line.split()
71         out['status'] = status
72         out['path'] = path
73         xml = subprocess.run(
74             shlex.split('svn log -l 1 {path} --xml'.format(path=path)),
75             stdout=subprocess.PIPE
76         )
77         xml_data = xml.stdout
78         xml_data = xml_data.decode("utf-8")
79         try:
80             root = ET.fromstring(xml_data)
81             for commit in root.findall('logentry'):
82                 author = commit.find('author').text
83                 shortmsg = commit.find('msg').text.split('\n')[0]
84                 out['author'] = author
85                 out['shortmsg'] = shortmsg
86                 out['rev'] = commit.attrib.get('revision', 'norev')
87                 svnmsg = "{status} {path}\t {shortmsg} | {rev} | {author}"
88                 print(svnmsg.format(**out))
89         except:
90             pass
91
92
93 if __name__ == '__main__':
94     sys.exit(main())