blob: eaf3a71a092d56d31defebbe2e2eabbb550057c1 [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
20parser.add_option('-c', '--condition', action='store', dest='condition',
21 help = 'the SQL condition to restrict your query by')
22parser.add_option('-s', '--separator', action='store', default = ' | ',
23 dest='separator', help = 'output separator')
24parser.add_option('-n', '--nocount', action='store_true', default=False,
25 help='Do not display line counts before each line')
26parser.add_option('-l', '--logpath', action='store_true', default=False,
27 help='Reformats the the tag column into a URL \
28 like http://autotest/results/[tag]. \
29 This will append the tag column if it isn\'t provided.')
30
31(options, args) = parser.parse_args()
32
mblighdeb758e2008-08-11 19:56:23 +000033if not options.condition:
34 parser.error('You must specify at least one condition.')
35
mblighbe630eb2008-08-01 16:41:48 +000036columns = options.columns.split(',')
37
38url_prefix = rpc.get_autotest_server() + '/results/'
39if options.logpath:
40 if 'tag' not in columns:
41 columns.append('tag')
42 tag_index=columns.index('tag')
43
44columns = [frontend.test_view_field_dict.get(field, field) for field in columns]
45
46if options.condition:
47 where = query_lib.parse_scrub_and_gen_condition(
48 options.condition, frontend.test_view_field_dict)
49else:
50 where = None
51
52# Grab the data
53db = db.db()
54count = 0
55for row in db.select(','.join(columns), 'test_view', where):
56 values = [str(x) for x in row]
57 if options.logpath:
58 values[tag_index] = url_prefix + values[tag_index]
59 if not options.nocount:
60 print '[%d] ' % count,
61 count += 1
62 print options.separator.join(values)