blob: b6c26126852ee9979cb5c4461bf5de96cc911b41 [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
33columns = options.columns.split(',')
34
35url_prefix = rpc.get_autotest_server() + '/results/'
36if options.logpath:
37 if 'tag' not in columns:
38 columns.append('tag')
39 tag_index=columns.index('tag')
40
41columns = [frontend.test_view_field_dict.get(field, field) for field in columns]
42
43if options.condition:
44 where = query_lib.parse_scrub_and_gen_condition(
45 options.condition, frontend.test_view_field_dict)
46else:
47 where = None
48
49# Grab the data
50db = db.db()
51count = 0
52for row in db.select(','.join(columns), 'test_view', where):
53 values = [str(x) for x in row]
54 if options.logpath:
55 values[tag_index] = url_prefix + values[tag_index]
56 if not options.nocount:
57 print '[%d] ' % count,
58 count += 1
59 print options.separator.join(values)