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', |
mbligh | 28afa73 | 2008-09-30 20:29:46 +0000 | [diff] [blame^] | 16 | default='*', help="""\ |
| 17 | By default or when using the -c flag: |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 18 | kernel hostname test label machine_group reason tag user status |
mbligh | 28afa73 | 2008-09-30 20:29:46 +0000 | [diff] [blame^] | 19 | |
| 20 | OR |
| 21 | |
| 22 | When using the -w flag: |
| 23 | test_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""") |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 24 | |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 25 | parser.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")) |
| 28 | parser.add_option('-w', '--where', action='store', dest='new_condition', |
| 29 | help=("The WHERE condition for the query witten in the 'new style' " |
mbligh | 28afa73 | 2008-09-30 20:29:46 +0000 | [diff] [blame^] | 30 | "condition syntax for new tko (see " |
| 31 | "http://autotest.kernel.org/wiki/TkoHowTo for more info)")) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 32 | parser.add_option('-s', '--separator', action='store', default = ' | ', |
| 33 | dest='separator', help = 'output separator') |
| 34 | parser.add_option('-n', '--nocount', action='store_true', default=False, |
| 35 | help='Do not display line counts before each line') |
| 36 | parser.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 | |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 43 | if 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) |
| 46 | elif 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' |
| 51 | elif options.new_condition: |
| 52 | where = options.new_condition.replace('%', '%%') |
| 53 | view = 'test_view_2' |
| 54 | tag = 'job_tag' |
| 55 | else: |
mbligh | deb758e | 2008-08-11 19:56:23 +0000 | [diff] [blame] | 56 | parser.error('You must specify at least one condition.') |
| 57 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 58 | columns = options.columns.split(',') |
| 59 | |
| 60 | url_prefix = rpc.get_autotest_server() + '/results/' |
| 61 | if options.logpath: |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 62 | if tag not in columns: |
| 63 | columns.append(tag) |
| 64 | tag_index=columns.index(tag) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 65 | |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 66 | if options.old_condition: |
| 67 | columns = [frontend.test_view_field_dict.get(field, field) |
| 68 | for field in columns] |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 69 | |
| 70 | # Grab the data |
| 71 | db = db.db() |
| 72 | count = 0 |
mbligh | 8dd5c6c | 2008-09-04 16:46:34 +0000 | [diff] [blame] | 73 | for row in db.select(','.join(columns), view, where): |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 74 | 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) |