blob: 3bd4c86881628d01c7647768e251a562e061541d [file] [log] [blame]
mbligh9bb92fe2007-09-12 15:54:23 +00001#!/usr/bin/python
2import os, re, db
3
mbligh8e1ab172007-09-13 17:29:56 +00004# 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.
mbligh9bb92fe2007-09-12 15:54:23 +000010
mbligh250300e2007-09-18 00:50:57 +000011html_root = 'http://test.kernel.org/google/'
12
mbligh9bb92fe2007-09-12 15:54:23 +000013class kernel:
mbligh8e1ab172007-09-13 17:29:56 +000014 @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
mbligh9bb92fe2007-09-12 15:54:23 +000021
mbligh8e1ab172007-09-13 17:29:56 +000022
23 def __init__(self, db, idx, hash, base, printable):
mbligh9bb92fe2007-09-12 15:54:23 +000024 self.db = db
mbligh8e1ab172007-09-13 17:29:56 +000025 self.idx = idx
mbligh9bb92fe2007-09-12 15:54:23 +000026 self.hash = hash
mbligh8e1ab172007-09-13 17:29:56 +000027 self.base = base
28 self.printable = printable
29 self.patches = [] # THIS SHOULD PULL IN PATCHES!
mbligh9bb92fe2007-09-12 15:54:23 +000030
31
32class test:
mbligh8e1ab172007-09-13 17:29:56 +000033 @classmethod
mbligh31d29c42007-09-27 00:51:33 +000034 def select(klass, db, where = {}, distinct = False):
mbligh8e1ab172007-09-13 17:29:56 +000035 fields = ['test_idx', 'job_idx', 'test', 'subdir',
36 'kernel_idx', 'status', 'reason', 'machine']
37 tests = []
mbligh31d29c42007-09-27 00:51:33 +000038 for row in db.select(','.join(fields), 'tests', where, distinct):
mbligh8e1ab172007-09-13 17:29:56 +000039 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
mbligh250300e2007-09-18 00:50:57 +000045 self.job = job(db, job_idx)
mbligh8e1ab172007-09-13 17:29:56 +000046 # self.machine = self.job.machine
mblighde7335d2007-09-26 16:53:20 +000047 self.testname = testname
mbligh8e1ab172007-09-13 17:29:56 +000048 self.subdir = subdir
mbligh16ae9262007-09-21 00:53:08 +000049 self.kernel = kernel.select(db, {'kernel_idx' : kernel_idx})[0]
mbligh8e1ab172007-09-13 17:29:56 +000050 self.status_num = status_num
51 self.status_word = db.status_word[status_num]
mbligh9bb92fe2007-09-12 15:54:23 +000052 self.reason = reason
mblighde7335d2007-09-26 16:53:20 +000053 if self.subdir:
54 self.url = html_root + self.job.tag + '/' + self.subdir
55 else:
56 self.subdir = None
mbligh16ae9262007-09-21 00:53:08 +000057
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
mbligh250300e2007-09-18 00:50:57 +000066
67class 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
mbligh8e1ab172007-09-13 17:29:56 +000075
mbligh16ae9262007-09-21 00:53:08 +000076class 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
mbligh8e1ab172007-09-13 17:29:56 +000092# class patch:
93# def __init__(self):
94# self.spec = None