mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | import os, re, db |
| 3 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 4 | # Pulling hierarchy: |
| 5 | # |
| 6 | # test pulls in (kernel, job, attributes, iterations) |
| 7 | # kernel pulls in (patches) |
| 8 | # |
| 9 | # Note that job does put pull test - test is the primary object. |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 10 | |
mbligh | 250300e | 2007-09-18 00:50:57 +0000 | [diff] [blame] | 11 | html_root = 'http://test.kernel.org/google/' |
| 12 | |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 13 | class kernel: |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 14 | @classmethod |
| 15 | def select(klass, db, where = {}): |
| 16 | fields = ['kernel_idx', 'kernel_hash', 'base', 'printable'] |
| 17 | kernels = [] |
| 18 | for row in db.select(','.join(fields), 'kernels', where): |
| 19 | kernels.append(klass(db, *row)) |
| 20 | return kernels |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 21 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 22 | |
| 23 | def __init__(self, db, idx, hash, base, printable): |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 24 | self.db = db |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 25 | self.idx = idx |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 26 | self.hash = hash |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 27 | self.base = base |
| 28 | self.printable = printable |
| 29 | self.patches = [] # THIS SHOULD PULL IN PATCHES! |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | class test: |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 33 | @classmethod |
mbligh | 31d29c4 | 2007-09-27 00:51:33 +0000 | [diff] [blame] | 34 | def select(klass, db, where = {}, distinct = False): |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 35 | fields = ['test_idx', 'job_idx', 'test', 'subdir', |
| 36 | 'kernel_idx', 'status', 'reason', 'machine'] |
| 37 | tests = [] |
mbligh | 31d29c4 | 2007-09-27 00:51:33 +0000 | [diff] [blame] | 38 | for row in db.select(','.join(fields), 'tests', where, distinct): |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 39 | tests.append(klass(db, *row)) |
| 40 | return tests |
| 41 | |
| 42 | |
| 43 | def __init__(self, db, test_idx, job_idx, testname, subdir, kernel_idx, status_num, reason, machine): |
| 44 | self.idx = test_idx |
mbligh | 250300e | 2007-09-18 00:50:57 +0000 | [diff] [blame] | 45 | self.job = job(db, job_idx) |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 46 | # self.machine = self.job.machine |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 47 | self.testname = testname |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 48 | self.subdir = subdir |
mbligh | 16ae926 | 2007-09-21 00:53:08 +0000 | [diff] [blame] | 49 | self.kernel = kernel.select(db, {'kernel_idx' : kernel_idx})[0] |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 50 | self.status_num = status_num |
| 51 | self.status_word = db.status_word[status_num] |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 52 | self.reason = reason |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 53 | if self.subdir: |
| 54 | self.url = html_root + self.job.tag + '/' + self.subdir |
| 55 | else: |
| 56 | self.subdir = None |
mbligh | 16ae926 | 2007-09-21 00:53:08 +0000 | [diff] [blame] | 57 | |
| 58 | self.iterations = {} |
| 59 | # Create a dictionary - dict{key} = [value1, value2, ....] |
| 60 | for i in iteration.select(db, {'test_idx' : test_idx}): |
| 61 | if self.iterations.has_key(i.key): |
| 62 | self.iterations[i.key].append(i.value) |
| 63 | else: |
| 64 | self.iterations[i.key] = [i.value] |
| 65 | |
mbligh | 250300e | 2007-09-18 00:50:57 +0000 | [diff] [blame] | 66 | |
| 67 | class job: |
| 68 | def __init__(self, db, job_idx): |
| 69 | where = {'job_idx' : job_idx} |
| 70 | rows = db.select('tag, machine', 'jobs', where) |
| 71 | if not rows: |
| 72 | return None |
| 73 | (self.tag, self.machine) = rows[0] |
| 74 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 75 | |
mbligh | 16ae926 | 2007-09-21 00:53:08 +0000 | [diff] [blame] | 76 | class iteration: |
| 77 | @classmethod |
| 78 | def select(klass, db, where): |
| 79 | fields = ['iteration', 'attribute', 'value'] |
| 80 | iterations = [] |
| 81 | rows = db.select(','.join(fields), 'iteration_result', where) |
| 82 | for row in rows: |
| 83 | iterations.append(klass(*row)) |
| 84 | return iterations |
| 85 | |
| 86 | |
| 87 | def __init__(self, iteration, key, value): |
| 88 | self.iteration = iteration |
| 89 | self.key = key |
| 90 | self.value = value |
| 91 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 92 | # class patch: |
| 93 | # def __init__(self): |
| 94 | # self.spec = None |