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 | |
| 12 | tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))) |
| 13 | sys.path.insert(0, tko) |
| 14 | import db, display, frontend |
| 15 | |
| 16 | db = db.db() |
| 17 | |
| 18 | def main(): |
| 19 | form = cgi.FieldStorage() |
| 20 | |
| 21 | if form.has_key('sql'): |
| 22 | sql = form['sql'].value |
| 23 | |
| 24 | if form.has_key('values'): |
| 25 | values = [val for val in form['values'].value.split(',')] |
| 26 | |
| 27 | if not sql: |
| 28 | return |
| 29 | if not values: |
| 30 | return |
| 31 | |
| 32 | tests = frontend.test.select_sql(db, sql, values) |
| 33 | |
| 34 | # get the list of tests/machines to populate the row and column header. |
| 35 | testname = [test.testname for test in tests] |
| 36 | machine_idx = [test.machine_idx for test in tests] |
| 37 | |
| 38 | # We dont want repetitions in the table row/column headers, |
| 39 | # so eliminate the dups. |
| 40 | uniq_test = list(set(testname)) |
| 41 | uniq_machine_idx = list(set(machine_idx)) |
| 42 | |
| 43 | header_row = [ display.box('', header = True) ] |
| 44 | for test_name in uniq_test: |
| 45 | header_row.append(display.box(test_name, header=True)) |
| 46 | matrix = [header_row] |
| 47 | for machine in uniq_machine_idx: |
| 48 | mach_name = db.select_sql('hostname', 'machines', |
| 49 | ' where machine_idx=%s', [str(machine)]) |
| 50 | row = [display.box(mach_name[0][0])] |
| 51 | for test_name in uniq_test: |
| 52 | testlist = [test for test in tests |
| 53 | if test.machine_idx == machine |
| 54 | and test.testname == test_name] |
| 55 | # url link to the first test. |
| 56 | # TODO: provide another level to show the different |
| 57 | # test results. |
| 58 | link = None |
| 59 | if testlist and testlist[0]: |
| 60 | link = testlist[0].url |
| 61 | box = display.status_count_box(db, testlist, link=link) |
| 62 | row.append(box) |
| 63 | matrix.append(row) |
| 64 | display.print_table(matrix) |
| 65 | |
| 66 | main() |
| 67 | |