add motd generator script
[freebsd-maintainer-scripts/.git] / sss.py
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
407c9abd 56 date = commit.find('date').text
6b8001db
SB
57 shortmsg = commit.find('msg').text.split('\n')[0]
58 out['author'] = author
59 out['shortmsg'] = shortmsg
114b5fb0 60 out['rev'] = commit.attrib.get('revision', 'norev')
407c9abd
SB
61 out['date'] = date.split('.')[0]
62 svnmsg = "{status} {path}\t {shortmsg} | {rev} | {author} | {date}"
114b5fb0 63 print(svnmsg.format(**out))
6b8001db
SB
64 except:
65 pass
66
67
68if __name__ == '__main__':
69 sys.exit(main())