sss: force to use python3 and clean unused variables
[freebsd-maintainer-scripts/.git] / sss
1 #!/usr/bin/env python3
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 Algorithm:
15
16 line = Parse output of svn up
17 foreach path in lines
18     xml data = svn log -rHEAD path --xml
19     author, shortmsg, status, path = parse xml data
20     print status, path, shortmsg, status, author
21 """
22
23 def valid_line(line):
24     if line.startswith('U ') or \
25        line.startswith('A ') or \
26        line.startswith('D '):
27         return True
28     else:
29         return False
30
31
32 def main():
33     src_path = os.path.expanduser('~/svn/src/')
34     ports_path = os.path.expanduser('~/svn/ports/')
35     svn_path = sys.argv[1] if len(sys.argv) == 2 else src_path
36     out = {}
37     data = subprocess.run(shlex.split('svn up {0}'.format(svn_path)),
38                           stdout=subprocess.PIPE).stdout
39     data = data.decode("utf-8")
40     for line in data.split('\n'):
41         if not valid_line(line):
42             continue
43         status, path = line.split()
44         out['status'] = status
45         out['path'] = path
46         xml = subprocess.run(
47             shlex.split('svn log -l 1 {path} --xml'.format(path=path)),
48             stdout=subprocess.PIPE
49         )
50         xml_data = xml.stdout
51         xml_data = xml_data.decode("utf-8")
52         try:
53             root = ET.fromstring(xml_data)
54             for commit in root.findall('logentry'):
55                 author = commit.find('author').text
56                 shortmsg = commit.find('msg').text.split('\n')[0]
57                 out['author'] = author
58                 out['shortmsg'] = shortmsg
59                 out['rev'] = commit.attrib.get('revision', 'norev')
60                 svnmsg = "{status} {path}\t {shortmsg} | {rev} | {author}"
61                 print(svnmsg.format(**out))
62         except:
63             pass
64
65
66 if __name__ == '__main__':
67     sys.exit(main())