s3:winbindd: use better debug messages than 'talloc_strdup failed'
[metze/samba-autobuild/.git] / selftest / format-subunit-json
1 #!/usr/bin/env python3
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 from __future__ import print_function
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         if line[:14] == 'elapsed-time: ':
23             name, time = line[14:].rsplit(':', 1)
24             results[name] = float(time)
25
26     json.dump(results, dest_f,
27               sort_keys=True, indent=2, separators=(',', ': '))
28
29
30 def main():
31     parser = optparse.OptionParser("format-subunit-json [options]")
32     parser.add_option("--verbose", action="store_true",
33                       help="ignored, for compatibility")
34     parser.add_option("--immediate", action="store_true",
35                       help="ignored, for compatibility")
36     parser.add_option("--prefix", type="string", default=".",
37                       help="Prefix to write summary.json to")
38     opts, args = parser.parse_args()
39
40     fn = os.path.join(opts.prefix, "summary.json")
41     f = open(fn, 'w')
42     json_formatter(sys.stdin, f)
43     f.close()
44     print()
45     print("A JSON file summarising these tests performance found in:")
46     print(" ", fn)
47
48
49 def handle_sigint(sig, stack):
50     sys.exit(0)
51
52 signal.signal(signal.SIGINT, handle_sigint)
53 main()