mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | Further display the tests in a matrix of the form tests X machines |
| 4 | to help understand the results selected from the previous form. |
| 5 | """ |
| 6 | |
| 7 | print "Content-type: text/html\n" |
| 8 | import cgi, cgitb, os, sys, re |
| 9 | sys.stdout.flush() |
| 10 | cgitb.enable() |
| 11 | |
jadmanski | 22ab069 | 2008-05-01 22:22:51 +0000 | [diff] [blame] | 12 | import common |
| 13 | from autotest_lib.tko import db, display, frontend |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 14 | |
| 15 | db = db.db() |
| 16 | |
| 17 | def main(): |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 18 | display.print_main_header() |
| 19 | |
| 20 | form = cgi.FieldStorage() |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 21 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 22 | if form.has_key('sql'): |
| 23 | sql = form['sql'].value |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 24 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 25 | if form.has_key('values'): |
| 26 | values = [val for val in form['values'].value.split(',')] |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 27 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 28 | if not sql: |
| 29 | return |
| 30 | if not values: |
| 31 | return |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 32 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 33 | tests = frontend.test.select_sql(db, sql, values) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 34 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 35 | # get the list of tests/machines to populate the row and column header. |
| 36 | testname = [test.testname for test in tests] |
| 37 | machine_idx = [test.machine_idx for test in tests] |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 38 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 39 | # We dont want repetitions in the table row/column headers, |
| 40 | # so eliminate the dups. |
| 41 | uniq_test = list(set(testname)) |
| 42 | uniq_machine_idx = list(set(machine_idx)) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 43 | |
mbligh | 15110b7 | 2009-01-13 23:33:33 +0000 | [diff] [blame] | 44 | header_row = [ display.box('', header = True) ] |
| 45 | for test_name in uniq_test: |
| 46 | header_row.append(display.box(test_name, header=True)) |
| 47 | matrix = [header_row] |
| 48 | for machine in uniq_machine_idx: |
| 49 | mach_name = db.select_sql('hostname', 'machines', |
| 50 | ' where machine_idx=%s', [str(machine)]) |
| 51 | row = [display.box(mach_name[0][0])] |
| 52 | for test_name in uniq_test: |
| 53 | testlist = [test for test in tests |
| 54 | if test.machine_idx == machine |
| 55 | and test.testname == test_name] |
| 56 | # url link to the first test. |
| 57 | # TODO: provide another level to show the different |
| 58 | # test results. |
| 59 | link = None |
| 60 | if testlist and testlist[0]: |
| 61 | link = testlist[0].url |
| 62 | box = display.status_count_box(db, testlist, link=link) |
| 63 | row.append(box) |
| 64 | matrix.append(row) |
| 65 | display.print_table(matrix) |
mbligh | 2e4e5df | 2007-11-05 17:22:46 +0000 | [diff] [blame] | 66 | |
| 67 | main() |