add sss script to add context information in svn up output
authorSofian Brabez <sbz@6dev.net>
Sat, 4 Nov 2017 17:26:50 +0000 (18:26 +0100)
committersbz <sbz@6dev.net>
Sat, 4 Nov 2017 17:26:50 +0000 (18:26 +0100)
sss [new file with mode: 0755]

diff --git a/sss b/sss
new file mode 100755 (executable)
index 0000000..f231974
--- /dev/null
+++ b/sss
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+
+"""
+sss - sbz svn status verbose on one line
+"""
+
+import os
+import shlex
+import subprocess
+import sys
+import xml.etree.ElementTree as ET
+
+"""
+line = Parse output of svn up
+foreach path in lines
+    xml data = svn log -rHEAD path --xml
+    author, shortmsg, status, path = parse xml data
+    print status, path, shortmsg, status, author
+"""
+
+x_data = """U    src/bin/dd/args.c
+U    src/bin/dd/conv.c
+U    src/bin/dd/dd.c
+U    src/bin/dd/dd.h
+U    src/bin/dd/position.c
+U    src/bin/pkill/pkill.c
+U    src/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h
+U    src/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
+U    src/cddl/usr.sbin/zfsd/zfsd_event.cc
+U    src/contrib/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
+U    src/contrib/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
+U    src/contrib/compiler-rt/lib/esan/esan_sideline_linux.cpp
+U    src/contrib/compiler-rt/lib/profile/InstrProfilingNameVar.c
+U   src/contrib/compiler-rt
+U   src/contrib/libc++
+"""
+
+x_xml_data = """<?xml version="1.0" encoding="UTF-8"?>
+<log>
+<logentry
+   revision="322826">
+<author>kevans</author>
+<date>2017-08-24T01:23:33.506520Z</date>
+<msg>bsdgrep: add a primitive literal matcher
+</msg>
+</logentry>
+</log>"""
+
+
+def valid_line(line):
+    if line.startswith('U ') or \
+       line.startswith('A ') or \
+       line.startswith('D '):
+        return True
+    else:
+        return False
+
+
+def main():
+    src_path = os.path.expanduser('~/svn/src/')
+    ports_path = os.path.expanduser('~/svn/ports/')
+    svn_path = sys.argv[1] if len(sys.argv) == 2 else src_path
+    out = {}
+    data = subprocess.run(shlex.split('svn up {0}'.format(svn_path)),
+                          stdout=subprocess.PIPE).stdout
+    data = data.decode("utf-8")
+    for line in data.split('\n'):
+        if not valid_line(line):
+            continue
+        status, path = line.split()
+        out['status'] = status
+        out['path'] = path
+        xml = subprocess.run(
+            shlex.split('svn log -l 1 {path} --xml'.format(path=path)),
+            stdout=subprocess.PIPE
+        )
+        xml_data = xml.stdout
+        xml_data = xml_data.decode("utf-8")
+        try:
+            root = ET.fromstring(xml_data)
+            for commit in root.findall('logentry'):
+                author = commit.find('author').text
+                shortmsg = commit.find('msg').text.split('\n')[0]
+                out['author'] = author
+                out['shortmsg'] = shortmsg
+                print("{status} {path}\t {shortmsg} | {author}".format(**out))
+        except:
+            pass
+
+
+if __name__ == '__main__':
+    sys.exit(main())