jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys, optparse |
| 4 | import common |
| 5 | from autotest_lib.cli import rpc |
| 6 | |
| 7 | |
| 8 | def parse_options(): |
| 9 | usage = "usage: %prog [options] job_id" |
| 10 | parser = optparse.OptionParser(usage=usage) |
| 11 | parser.add_option("-m", "--machine", dest="machine") |
| 12 | parser.add_option("-t", "--test", dest="test") |
| 13 | parser.add_option("-T", "--type", dest="type", type="choice", |
| 14 | choices=["all", "test", "iteration", "attr", "perf"]) |
| 15 | parser.add_option("-k", "--key", dest="key") |
| 16 | parser.set_defaults(type="all") |
| 17 | options, args = parser.parse_args() |
| 18 | options.show_test_keyvals = options.type in ("all", "test") |
| 19 | options.show_attr_keyvals = options.type in ("all", "iteration", "attr") |
| 20 | options.show_perf_keyvals = options.type in ("all", "iteration", "perf") |
| 21 | options.show_iter_keyvals = ( |
| 22 | options.show_perf_keyvals or options.show_attr_keyvals) |
| 23 | return parser, options, args |
| 24 | |
| 25 | |
| 26 | def print_keyvals(keyval, format_string, options): |
| 27 | for key, value in keyval.iteritems(): |
| 28 | if not options.key or key == options.key: |
| 29 | print format_string % (key, value) |
| 30 | |
| 31 | |
| 32 | def print_views(test_views, options): |
| 33 | for view in test_views: |
| 34 | if not options.machine: |
| 35 | print "Machine: %s" % view["hostname"] |
| 36 | if not options.test: |
| 37 | print "Test: %s" % view["test_name"] |
| 38 | if options.show_test_keyvals: |
| 39 | print "Test Attributes:" |
| 40 | print_keyvals(view["attributes"], "\t%s = %s", options) |
| 41 | if options.show_iter_keyvals: |
| 42 | print "Iteration Attributes:" |
| 43 | for i, iteration in enumerate(view["iterations"]): |
| 44 | print "\tIteration #%d:" % (i + 1) |
| 45 | if options.show_attr_keyvals: |
| 46 | print_keyvals(iteration["attr"], "\t\t%s(attr) = %s", |
| 47 | options) |
| 48 | if options.show_perf_keyvals: |
| 49 | print_keyvals(iteration["perf"], "\t\t%s(perf) = %s", |
| 50 | options) |
| 51 | print |
| 52 | |
| 53 | |
| 54 | def main(): |
| 55 | parser, options, args = parse_options() |
jadmanski | 2ec03f2 | 2009-01-29 15:36:39 +0000 | [diff] [blame] | 56 | if not args: |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 57 | parser.print_help() |
jadmanski | 2ec03f2 | 2009-01-29 15:36:39 +0000 | [diff] [blame] | 58 | return |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 59 | |
jadmanski | 2ec03f2 | 2009-01-29 15:36:39 +0000 | [diff] [blame] | 60 | query_filter = {} |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 61 | if options.machine: |
| 62 | query_filter["hostname"] = options.machine |
| 63 | if options.test: |
| 64 | query_filter["test_name"] = options.test |
| 65 | |
jadmanski | 3086aa6 | 2009-01-28 18:14:07 +0000 | [diff] [blame] | 66 | comm = rpc.tko_comm() |
jadmanski | 2ec03f2 | 2009-01-29 15:36:39 +0000 | [diff] [blame] | 67 | test_views = [] |
| 68 | for job_id in args: |
| 69 | query_filter["job_tag__startswith"] = "%s-" % job_id |
| 70 | test_views += comm.run("get_detailed_test_views", **query_filter) |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 71 | print_views(test_views, options) |
| 72 | |
| 73 | |
| 74 | if __name__ == "__main__": |
| 75 | main() |