blob: 4ffef26a3cd1fb6495479687424f3095965bd54d [file] [log] [blame]
Selects all rows and columns that satisfy the condition specified
and prints the matrix.
import optparse
import common
from autotest_lib.cli import rpc
from autotest_lib.database import database_connection
# First do all the options parsing
parser = optparse.OptionParser()
'-C', '--columns', action='store', dest='columns',
help='Comma-separated list of column names to display')
parser.add_option('-w', '--where', action='store', dest='condition',
help=("The WHERE condition for the query witten in the 'new style' "
"condition syntax for new tko (see "
" for more info)"))
'--test-attribute-field', action='append', default=[],
help='Specifies a test attribute to include as a field. The attribute '
'value will be available as a field named attribute_<attribute '
'name>. This option may be specified multiple times. Filtering '
'must be done slightly differently -- see '
' '
'for more details.')
parser.add_option('--test-label-field', action='append', default=[],
help='Specifies a test label to include as a field. See '
'--attribute-field for more details')
parser.add_option('--iteration-result-field', action='append', default=[],
help='Specifies an iteration result to include as a field. '
'See --attribute-field for more details. Note that '
'this causes the rows returned to represent iterations '
'rather than plain test results.')
parser.add_option('--machine-label-field', action='append', default=[],
help='Specifies a machine label to include as a field. See '
'--attribute-field for more details')
parser.add_option('--job-keyval-field', action='append', default=[],
help='Specifies a job keyval to include as a field. See '
'--attribute-field for more details')
parser.add_option('--iteration-attribute-field', action='append', default=[],
help='Specifies an iteration attribute to include as a '
'field. See --attribute-field for more details. Note '
'that this causes the rows returned to represent '
'iterations rather than plain test results.')
parser.add_option('-s', '--separator', action='store', default = ' | ',
dest='separator', help = 'output separator')
parser.add_option('-n', '--nocount', action='store_true', default=False,
help='Do not display line counts before each line')
parser.add_option('-l', '--logpath', action='store_true', default=False,
help='Reformats the the tag column into a URL \
like http://autotest/results/[tag]. \
This will append the tag column if it isn\'t provided.')
parser.add_option('--host-label', action='store', dest='host_label',
help=('Return results only for machines currently '
'in the specified label'))
(options, args) = parser.parse_args()
if not options.condition:
parser.error('You must specify a condition.')
where = options.condition.replace('%', '%%')
tag = 'job_tag'
columns = options.columns.split(',')
url_prefix = rpc.get_autotest_server() + '/results/'
if options.logpath:
if tag not in columns:
if options.host_label:
database = database_connection.DatabaseConnection("AUTOTEST_WEB")
sql = ("SELECT hostname FROM afe_labels JOIN afe_hosts_labels "
"ON JOIN afe_hosts "
"ON WHERE name=%s")
results = database.execute(sql, options.host_label)
hosts = [row[0] for row in results]
where += " AND hostname IN ('" + "','".join(hosts) + "')"
# Grab the data
tko = rpc.tko_comm()
count = 0
test_views =
'get_test_views', extra_where=where,
for test_view in test_views:
values = [str(test_view[column]) for column in columns]
if options.logpath:
values[tag_index] = url_prefix + values[tag_index]
if not options.nocount:
print '[%d] ' % count,
count += 1
print options.separator.join(values)