1#!/usr/bin/env python
2
3##########################################################################
4# Copyright (c) 2009, ETH Zurich.
5# All rights reserved.
6#
7# This file is distributed under the terms in the attached LICENSE file.
8# If you do not find this file, copies can be found by writing to:
9# ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
10##########################################################################
11
12import os, optparse, re
13import harness, debug, tests
14
15
16def parse_args():
17    p = optparse.OptionParser(usage='Usage: %prog [options] RESULTDIR...',
18            description='Reprocess raw results from scalebench/harness runs')
19    debug.addopts(p, 'debuglevel')
20    options, dirs = p.parse_args()
21
22    if len(dirs) == 0:
23        p.error('no result directories specified')
24
25    # check validity of result dirs
26    for d in dirs:
27        if not (os.path.isdir(d) and os.access(d, os.W_OK)
28                and os.access(os.path.join(d, 'description.txt'), os.R_OK)):
29            p.error('invalid results directory %s' % d)
30
31    debug.current_level = options.debuglevel
32    return dirs
33
34
35def main(dirs):
36    for dirname in dirs:
37        debug.log('reprocessing %s' % dirname)
38        debug.verbose('parse %s/description.txt for test' % dirname)
39        testname = test = None
40        f = open(os.path.join(dirname, 'description.txt'), 'r')
41        for line in f:
42            m = re.match(r'test:\s+(.*)', line)
43            if m:
44                testname = m.group(1)
45                break
46        f.close()
47
48        if not testname:
49            debug.error('unable to parse description for %s, skipped' % dirname)
50            continue
51
52        debug.verbose('locate test "%s"' % testname)
53        for t in tests.all_tests:
54            if t.name.lower() == testname.lower():
55                test = t(None) # XXX: dummy options
56        if not test:
57            debug.error('unknown test "%s" in %s, skipped' % (testname, dirname))
58            continue
59
60        debug.verbose('reprocess results')
61        h = harness.Harness()
62        h.process_results(test, dirname)
63
64if __name__ == "__main__":
65    main(parse_args())
66