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 | |
| 20 | parser.add_option('-c', '--condition', action='store', dest='condition', |
| 21 | help = 'the SQL condition to restrict your query by') |
| 22 | parser.add_option('-s', '--separator', action='store', default = ' | ', |
| 23 | dest='separator', help = 'output separator') |
| 24 | parser.add_option('-n', '--nocount', action='store_true', default=False, |
| 25 | help='Do not display line counts before each line') |
| 26 | parser.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 | |
| 33 | columns = options.columns.split(',') |
| 34 | |
| 35 | url_prefix = rpc.get_autotest_server() + '/results/' |
| 36 | if options.logpath: |
| 37 | if 'tag' not in columns: |
| 38 | columns.append('tag') |
| 39 | tag_index=columns.index('tag') |
| 40 | |
| 41 | columns = [frontend.test_view_field_dict.get(field, field) for field in columns] |
| 42 | |
| 43 | if options.condition: |
| 44 | where = query_lib.parse_scrub_and_gen_condition( |
| 45 | options.condition, frontend.test_view_field_dict) |
| 46 | else: |
| 47 | where = None |
| 48 | |
| 49 | # Grab the data |
| 50 | db = db.db() |
| 51 | count = 0 |
| 52 | for 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) |