blob: 78387879de5ba7b071e90eb7aa0506a524ebe1bf [file] [log] [blame]
mblighbe630eb2008-08-01 16:41:48 +00001#!/usr/bin/python
2"""
3Selects all rows and columns that satisfy the condition specified
4and prints the matrix.
5"""
6import sys, os, re, optparse
7import common
8from autotest_lib.cli import rpc
9from autotest_lib.tko import display, frontend, db, query_lib
10from autotest_lib.client.bin import kernel_versions
11
12
13# First do all the options parsing
14parser = optparse.OptionParser()
15parser.add_option('-C', '--columns', action='store', dest='columns',
mbligh28afa732008-09-30 20:29:46 +000016 default='*', help="""\
17By default or when using the -c flag:
mblighbe630eb2008-08-01 16:41:48 +000018kernel hostname test label machine_group reason tag user status
mbligh28afa732008-09-30 20:29:46 +000019
20OR
21
22When using the -w flag:
23test_idx test_name reason test_started_time test_finished_time job_tag job_name job_owner job_queued_time job_started_time job_finished_time hostname platform kernel status""")
mblighbe630eb2008-08-01 16:41:48 +000024
mbligh8dd5c6c2008-09-04 16:46:34 +000025parser.add_option('-c', '--condition', action='store', dest='old_condition',
26 help=("The WHERE condition for the query witten in the 'old style' "
27 "condition syntax for the original tko"))
28parser.add_option('-w', '--where', action='store', dest='new_condition',
29 help=("The WHERE condition for the query witten in the 'new style' "
mbligh28afa732008-09-30 20:29:46 +000030 "condition syntax for new tko (see "
31 "http://autotest.kernel.org/wiki/TkoHowTo for more info)"))
mblighbe630eb2008-08-01 16:41:48 +000032parser.add_option('-s', '--separator', action='store', default = ' | ',
33 dest='separator', help = 'output separator')
34parser.add_option('-n', '--nocount', action='store_true', default=False,
35 help='Do not display line counts before each line')
36parser.add_option('-l', '--logpath', action='store_true', default=False,
37 help='Reformats the the tag column into a URL \
38 like http://autotest/results/[tag]. \
39 This will append the tag column if it isn\'t provided.')
40
41(options, args) = parser.parse_args()
42
mbligh8dd5c6c2008-09-04 16:46:34 +000043if options.old_condition and options.new_condition:
44 msg = 'You cannot specify WHERE clauses in both the old and new style.'
45 parser.error(msg)
46elif options.old_condition:
47 where = query_lib.parse_scrub_and_gen_condition(
48 options.old_condition, frontend.test_view_field_dict)
49 view = 'test_view'
50 tag = 'tag'
51elif options.new_condition:
52 where = options.new_condition.replace('%', '%%')
53 view = 'test_view_2'
54 tag = 'job_tag'
55else:
mblighdeb758e2008-08-11 19:56:23 +000056 parser.error('You must specify at least one condition.')
57
mblighbe630eb2008-08-01 16:41:48 +000058columns = options.columns.split(',')
59
60url_prefix = rpc.get_autotest_server() + '/results/'
61if options.logpath:
mbligh8dd5c6c2008-09-04 16:46:34 +000062 if tag not in columns:
63 columns.append(tag)
64 tag_index=columns.index(tag)
mblighbe630eb2008-08-01 16:41:48 +000065
mbligh8dd5c6c2008-09-04 16:46:34 +000066if options.old_condition:
67 columns = [frontend.test_view_field_dict.get(field, field)
68 for field in columns]
mblighbe630eb2008-08-01 16:41:48 +000069
70# Grab the data
71db = db.db()
72count = 0
mbligh8dd5c6c2008-09-04 16:46:34 +000073for row in db.select(','.join(columns), view, where):
mblighbe630eb2008-08-01 16:41:48 +000074 values = [str(x) for x in row]
75 if options.logpath:
76 values[tag_index] = url_prefix + values[tag_index]
77 if not options.nocount:
78 print '[%d] ' % count,
79 count += 1
80 print options.separator.join(values)