sss: force to use python3 and clean unused variables
[freebsd-maintainer-scripts/.git] / sss
CommitLineData
b1c75a53 1#!/usr/bin/env python3
6b8001db
SB
2
3"""
4sss - sbz svn status verbose on one line
5"""
6
7import os
8import shlex
9import subprocess
10import sys
11import xml.etree.ElementTree as ET
12
13"""
b1c75a53
SB
14Algorithm:
15
6b8001db
SB
16line = Parse output of svn up
17foreach 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
6b8001db
SB
23def 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
32def 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
114b5fb0
SB
59 out['rev'] = commit.attrib.get('revision', 'norev')
60 svnmsg = "{status} {path}\t {shortmsg} | {rev} | {author}"
61 print(svnmsg.format(**out))
6b8001db
SB
62 except:
63 pass
64
65
66if __name__ == '__main__':
67 sys.exit(main())