selftest: Check that LDAP is available during RODC startup
[nivanova/samba-autobuild/.git] / selftest / format-subunit-json
1 #!/usr/bin/env python
2 # Copyright (C) 2008-2010 Jelmer Vernooij <jelmer@samba.org>
3 # Copyright (C) 2016 Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
4 # Published under the GNU GPL, v3 or later
5
6 import optparse
7 import os
8 import signal
9 import sys
10 import json
11
12 sys.path.insert(0, "bin/python")
13
14
15 def json_formatter(src_f, dest_f):
16     """We're not even pretending to be a TestResult subclass; just read
17     from stdin and look for elapsed-time tags."""
18     results = {}
19
20     for line in src_f:
21         line = line.strip()
22         print >>sys.stderr, line
23         if line[:14] == 'elapsed-time: ':
24             name, time = line[14:].rsplit(':', 1)
25             results[name] = float(time)
26
27     json.dump(results, dest_f,
28               sort_keys=True, indent=2, separators=(',', ': '))
29
30
31 def main():
32     parser = optparse.OptionParser("format-subunit-json [options]")
33     parser.add_option("--verbose", action="store_true",
34                       help="ignored, for compatibility")
35     parser.add_option("--immediate", action="store_true",
36                       help="ignored, for compatibility")
37     parser.add_option("--prefix", type="string", default=".",
38                       help="Prefix to write summary.json to")
39     opts, args = parser.parse_args()
40
41     fn = os.path.join(opts.prefix, "summary.json")
42     f = open(fn, 'w')
43     json_formatter(sys.stdin, f)
44     f.close()
45     print
46     print "A JSON file summarising these tests performance found in:"
47     print " ", fn
48
49
50 def handle_sigint(sig, stack):
51     sys.exit(0)
52
53 signal.signal(signal.SIGINT, handle_sigint)
54 main()