blob: c48c5a18b2eb4ca26891daed135fba4b0695f6ca [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
mbligh2aaeb672007-10-01 14:54:18 +000067 def __init__(self, db, test_idx, job_idx, testname, subdir, kernel_idx, status_num, reason, machine_idx):
mbligh8e1ab172007-09-13 17:29:56 +000068 self.idx = test_idx
mbligh250300e2007-09-18 00:50:57 +000069 self.job = job(db, job_idx)
mblighde7335d2007-09-26 16:53:20 +000070 self.testname = testname
mbligh8e1ab172007-09-13 17:29:56 +000071 self.subdir = subdir
mbligh50a25252007-09-27 15:26:17 +000072 self.kernel_idx = kernel_idx
73 self.__kernel = None
74 self.__iterations = None
mbligh2aaeb672007-10-01 14:54:18 +000075 self.machine_idx = machine_idx
76 self.__machine = None
mbligh8e1ab172007-09-13 17:29:56 +000077 self.status_num = status_num
78 self.status_word = db.status_word[status_num]
mbligh9bb92fe2007-09-12 15:54:23 +000079 self.reason = reason
mbligh50a25252007-09-27 15:26:17 +000080 self.db = db
mblighde7335d2007-09-26 16:53:20 +000081 if self.subdir:
82 self.url = html_root + self.job.tag + '/' + self.subdir
83 else:
mbligh676510c2007-09-28 01:28:12 +000084 self.url = None
mbligh16ae9262007-09-21 00:53:08 +000085
mbligh50a25252007-09-27 15:26:17 +000086
87
88 def iterations(self):
89 """
90 Caching function for iterations
91 """
92 if not self.__iterations:
93 self.__iterations = {}
94 # A dictionary - dict{key} = [value1, value2, ....]
95 where = {'test_idx' : self.idx}
96 for i in iteration.select(self.db, where):
97 if self.__iterations.has_key(i.key):
98 self.__iterations[i.key].append(i.value)
99 else:
100 self.__iterations[i.key] = [i.value]
101 return self.__iterations
102
103
104 def kernel(self):
105 """
106 Caching function for kernels
107 """
108 if not self.__kernel:
109 where = {'kernel_idx' : self.kernel_idx}
110 self.__kernel = kernel.select(self.db, where)[0]
111 return self.__kernel
112
mbligh250300e2007-09-18 00:50:57 +0000113
mbligh2aaeb672007-10-01 14:54:18 +0000114 def machine(self):
115 """
116 Caching function for kernels
117 """
118 if not self.__machine:
119 where = {'machine_idx' : self.machine_idx}
120 self.__machine = machine.select(self.db, where)[0]
121 return self.__machine
122
123
mbligh250300e2007-09-18 00:50:57 +0000124class job:
125 def __init__(self, db, job_idx):
126 where = {'job_idx' : job_idx}
mbligh2aaeb672007-10-01 14:54:18 +0000127 rows = db.select('tag, machine_idx', 'jobs', where)
mbligh250300e2007-09-18 00:50:57 +0000128 if not rows:
129 return None
mbligh2aaeb672007-10-01 14:54:18 +0000130 (self.tag, self.machine_idx) = rows[0]
mbligh250300e2007-09-18 00:50:57 +0000131
mbligh8e1ab172007-09-13 17:29:56 +0000132
mbligh16ae9262007-09-21 00:53:08 +0000133class iteration:
134 @classmethod
135 def select(klass, db, where):
136 fields = ['iteration', 'attribute', 'value']
137 iterations = []
138 rows = db.select(','.join(fields), 'iteration_result', where)
139 for row in rows:
140 iterations.append(klass(*row))
141 return iterations
142
143
144 def __init__(self, iteration, key, value):
145 self.iteration = iteration
146 self.key = key
147 self.value = value
148
mbligh8e1ab172007-09-13 17:29:56 +0000149# class patch:
150# def __init__(self):
151# self.spec = None