mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | Selects all rows and columns that satisfy the condition specified |
| 4 | and prints the matrix. |
| 5 | """ |
| 6 | import sys, os, re, optparse |
| 7 | import common |
| 8 | from autotest_lib.cli import rpc |
| 9 | from autotest_lib.tko import display, frontend, db, query_lib |
| 10 | from autotest_lib.client.bin import kernel_versions |
| 11 | |
| 12 | |
| 13 | # First do all the options parsing |
| 14 | parser = optparse.OptionParser() |
| 15 | parser.add_option('-C', '--columns', action='store', dest='columns', |
| 16 | default='*', help='''columns to select: |
| 17 | kernel hostname test label machine_group reason tag user status |
| 18 | ''') |
| 19 | |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame^] | 20 | parser.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")) |
| 23 | parser.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")) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 26 | parser.add_option('-s', '--separator', action='store', default = ' | ', |
| 27 | dest='separator', help = 'output separator') |
| 28 | parser.add_option('-n', '--nocount', action='store_true', default=False, |
| 29 | help='Do not display line counts before each line') |
| 30 | parser.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 | |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame^] | 37 | if 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) |
| 40 | elif 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' |
| 45 | elif options.new_condition: |
| 46 | where = options.new_condition.replace('%', '%%') |
| 47 | view = 'test_view_2' |
| 48 | tag = 'job_tag' |
| 49 | else: |
mbligh | deb758e | 2008-08-11 19:56:23 +0000 | [diff] [blame] | 50 | parser.error('You must specify at least one condition.') |
| 51 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 52 | columns = options.columns.split(',') |
| 53 | |
| 54 | url_prefix = rpc.get_autotest_server() + '/results/' |
| 55 | if options.logpath: |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame^] | 56 | if tag not in columns: |
| 57 | columns.append(tag) |
| 58 | tag_index=columns.index(tag) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 59 | |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame^] | 60 | if options.old_condition: |
| 61 | columns = [frontend.test_view_field_dict.get(field, field) |
| 62 | for field in columns] |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 63 | |
| 64 | # Grab the data |
| 65 | db = db.db() |
| 66 | count = 0 |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame^] | 67 | for row in db.select(','.join(columns), view, where): |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 68 | 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) |