blob: 203c65a7e45b7af2bb50344d305363cc83be0a0a [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',
16 default='*', help='''columns to select:
17kernel hostname test label machine_group reason tag user status
18''')
19
mbligh8dd5c6c2008-09-04 16:46:34 +000020parser.add_option('-c', '--condition', action='store', dest='old_condition',
21 help=("The WHERE condition for the query witten in the 'old style' "
22 "condition syntax for the original tko"))
23parser.add_option('-w', '--where', action='store', dest='new_condition',
24 help=("The WHERE condition for the query witten in the 'new style' "
25 "condition syntax for the new tko"))
mblighbe630eb2008-08-01 16:41:48 +000026parser.add_option('-s', '--separator', action='store', default = ' | ',
27 dest='separator', help = 'output separator')
28parser.add_option('-n', '--nocount', action='store_true', default=False,
29 help='Do not display line counts before each line')
30parser.add_option('-l', '--logpath', action='store_true', default=False,
31 help='Reformats the the tag column into a URL \
32 like http://autotest/results/[tag]. \
33 This will append the tag column if it isn\'t provided.')
34
35(options, args) = parser.parse_args()
36
mbligh8dd5c6c2008-09-04 16:46:34 +000037if options.old_condition and options.new_condition:
38 msg = 'You cannot specify WHERE clauses in both the old and new style.'
39 parser.error(msg)
40elif options.old_condition:
41 where = query_lib.parse_scrub_and_gen_condition(
42 options.old_condition, frontend.test_view_field_dict)
43 view = 'test_view'
44 tag = 'tag'
45elif options.new_condition:
46 where = options.new_condition.replace('%', '%%')
47 view = 'test_view_2'
48 tag = 'job_tag'
49else:
mblighdeb758e2008-08-11 19:56:23 +000050 parser.error('You must specify at least one condition.')
51
mblighbe630eb2008-08-01 16:41:48 +000052columns = options.columns.split(',')
53
54url_prefix = rpc.get_autotest_server() + '/results/'
55if options.logpath:
mbligh8dd5c6c2008-09-04 16:46:34 +000056 if tag not in columns:
57 columns.append(tag)
58 tag_index=columns.index(tag)
mblighbe630eb2008-08-01 16:41:48 +000059
mbligh8dd5c6c2008-09-04 16:46:34 +000060if options.old_condition:
61 columns = [frontend.test_view_field_dict.get(field, field)
62 for field in columns]
mblighbe630eb2008-08-01 16:41:48 +000063
64# Grab the data
65db = db.db()
66count = 0
mbligh8dd5c6c2008-09-04 16:46:34 +000067for row in db.select(','.join(columns), view, where):
mblighbe630eb2008-08-01 16:41:48 +000068 values = [str(x) for x in row]
69 if options.logpath:
70 values[tag_index] = url_prefix + values[tag_index]
71 if not options.nocount:
72 print '[%d] ' % count,
73 count += 1
74 print options.separator.join(values)