blob: 7ffe8d2489a869858e8fd98da41c35b3ad34b8c9 [file] [log] [blame]
mbligh9bb92fe2007-09-12 15:54:23 +00001#!/usr/bin/python
mbligh2aaeb672007-10-01 14:54:18 +00002import os, re, db, sys
mbligh9bb92fe2007-09-12 15:54:23 +00003
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
mbligh2aaeb672007-10-01 14:54:18 +000011tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
12root_url_file = os.path.join(tko, '.root_url')
13if os.path.exists(root_url_file):
14 html_root = open(root_url_file, 'r').readline().rstrip()
15else:
16 html_root = 'http://test.kernel.org/google/'
17
18
19class machine:
20 @classmethod
21 def select(klass, db, where = {}):
22 fields = ['machine_idx', 'hostname', 'machine_group', 'owner']
23 machines = []
24 for row in db.select(','.join(fields), 'machines', where):
25 machines.append(klass(db, *row))
26 return machines
27
28
29 def __init__(self, db, idx, hostname, group, owner):
30 self.db = db
31 self.idx = idx
32 self.hostname = hostname
33 self.group = group
34 self.owner = owner
35
mbligh250300e2007-09-18 00:50:57 +000036
mbligh9bb92fe2007-09-12 15:54:23 +000037class kernel:
mbligh8e1ab172007-09-13 17:29:56 +000038 @classmethod
39 def select(klass, db, where = {}):
40 fields = ['kernel_idx', 'kernel_hash', 'base', 'printable']
41 kernels = []
42 for row in db.select(','.join(fields), 'kernels', where):
43 kernels.append(klass(db, *row))
44 return kernels
mbligh9bb92fe2007-09-12 15:54:23 +000045
mbligh8e1ab172007-09-13 17:29:56 +000046
47 def __init__(self, db, idx, hash, base, printable):
mbligh9bb92fe2007-09-12 15:54:23 +000048 self.db = db
mbligh8e1ab172007-09-13 17:29:56 +000049 self.idx = idx
mbligh9bb92fe2007-09-12 15:54:23 +000050 self.hash = hash
mbligh8e1ab172007-09-13 17:29:56 +000051 self.base = base
52 self.printable = printable
53 self.patches = [] # THIS SHOULD PULL IN PATCHES!
mbligh9bb92fe2007-09-12 15:54:23 +000054
55
56class test:
mbligh8e1ab172007-09-13 17:29:56 +000057 @classmethod
mbligh31d29c42007-09-27 00:51:33 +000058 def select(klass, db, where = {}, distinct = False):
mbligh8e1ab172007-09-13 17:29:56 +000059 fields = ['test_idx', 'job_idx', 'test', 'subdir',
mbligh2aaeb672007-10-01 14:54:18 +000060 'kernel_idx', 'status', 'reason', 'machine_idx']
mbligh8e1ab172007-09-13 17:29:56 +000061 tests = []
mbligh31d29c42007-09-27 00:51:33 +000062 for row in db.select(','.join(fields), 'tests', where, distinct):
mbligh8e1ab172007-09-13 17:29:56 +000063 tests.append(klass(db, *row))
64 return tests
65
66
mbligh414c69e2007-10-05 15:13:06 +000067 @classmethod
68 def select_sql(klass, db, sql, values):
69 fields = ['test_idx', 'job_idx', 'test', 'subdir',
70 'kernel_idx', 'status', 'reason', 'machine_idx']
71 fields = ['t.'+field for field in fields]
72 rows = db.select_sql(','.join(fields), 'tests', sql, values)
73 return [klass(db, *row) for row in rows]
74
75
mbligh2aaeb672007-10-01 14:54:18 +000076 def __init__(self, db, test_idx, job_idx, testname, subdir, kernel_idx, status_num, reason, machine_idx):
mbligh8e1ab172007-09-13 17:29:56 +000077 self.idx = test_idx
mbligh250300e2007-09-18 00:50:57 +000078 self.job = job(db, job_idx)
mblighde7335d2007-09-26 16:53:20 +000079 self.testname = testname
mbligh8e1ab172007-09-13 17:29:56 +000080 self.subdir = subdir
mbligh50a25252007-09-27 15:26:17 +000081 self.kernel_idx = kernel_idx
82 self.__kernel = None
83 self.__iterations = None
mbligh2aaeb672007-10-01 14:54:18 +000084 self.machine_idx = machine_idx
85 self.__machine = None
mbligh8e1ab172007-09-13 17:29:56 +000086 self.status_num = status_num
87 self.status_word = db.status_word[status_num]
mbligh9bb92fe2007-09-12 15:54:23 +000088 self.reason = reason
mbligh50a25252007-09-27 15:26:17 +000089 self.db = db
mblighde7335d2007-09-26 16:53:20 +000090 if self.subdir:
91 self.url = html_root + self.job.tag + '/' + self.subdir
92 else:
mbligh676510c2007-09-28 01:28:12 +000093 self.url = None
mbligh16ae9262007-09-21 00:53:08 +000094
mbligh50a25252007-09-27 15:26:17 +000095
96
97 def iterations(self):
98 """
99 Caching function for iterations
100 """
101 if not self.__iterations:
102 self.__iterations = {}
103 # A dictionary - dict{key} = [value1, value2, ....]
104 where = {'test_idx' : self.idx}
105 for i in iteration.select(self.db, where):
106 if self.__iterations.has_key(i.key):
107 self.__iterations[i.key].append(i.value)
108 else:
109 self.__iterations[i.key] = [i.value]
110 return self.__iterations
111
112
113 def kernel(self):
114 """
115 Caching function for kernels
116 """
117 if not self.__kernel:
118 where = {'kernel_idx' : self.kernel_idx}
119 self.__kernel = kernel.select(self.db, where)[0]
120 return self.__kernel
121
mbligh250300e2007-09-18 00:50:57 +0000122
mbligh2aaeb672007-10-01 14:54:18 +0000123 def machine(self):
124 """
125 Caching function for kernels
126 """
127 if not self.__machine:
128 where = {'machine_idx' : self.machine_idx}
129 self.__machine = machine.select(self.db, where)[0]
130 return self.__machine
131
132
mbligh250300e2007-09-18 00:50:57 +0000133class job:
134 def __init__(self, db, job_idx):
135 where = {'job_idx' : job_idx}
mbligh2aaeb672007-10-01 14:54:18 +0000136 rows = db.select('tag, machine_idx', 'jobs', where)
mbligh250300e2007-09-18 00:50:57 +0000137 if not rows:
138 return None
mbligh2aaeb672007-10-01 14:54:18 +0000139 (self.tag, self.machine_idx) = rows[0]
mbligh250300e2007-09-18 00:50:57 +0000140
mbligh8e1ab172007-09-13 17:29:56 +0000141
mbligh16ae9262007-09-21 00:53:08 +0000142class iteration:
143 @classmethod
144 def select(klass, db, where):
145 fields = ['iteration', 'attribute', 'value']
146 iterations = []
147 rows = db.select(','.join(fields), 'iteration_result', where)
148 for row in rows:
149 iterations.append(klass(*row))
150 return iterations
151
152
153 def __init__(self, iteration, key, value):
154 self.iteration = iteration
155 self.key = key
156 self.value = value
157
mbligh8e1ab172007-09-13 17:29:56 +0000158# class patch:
159# def __init__(self):
160# self.spec = None