blob: 52802c19a8b9c1991694e726c19d0d5fe1bf1b50 [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
mbligh50a25252007-09-27 15:26:17 +000049 self.kernel_idx = kernel_idx
50 self.__kernel = None
51 self.__iterations = None
mbligh8e1ab172007-09-13 17:29:56 +000052 self.status_num = status_num
53 self.status_word = db.status_word[status_num]
mbligh9bb92fe2007-09-12 15:54:23 +000054 self.reason = reason
mbligh50a25252007-09-27 15:26:17 +000055 self.db = db
mblighde7335d2007-09-26 16:53:20 +000056 if self.subdir:
57 self.url = html_root + self.job.tag + '/' + self.subdir
58 else:
59 self.subdir = None
mbligh16ae9262007-09-21 00:53:08 +000060
mbligh50a25252007-09-27 15:26:17 +000061
62
63 def iterations(self):
64 """
65 Caching function for iterations
66 """
67 if not self.__iterations:
68 self.__iterations = {}
69 # A dictionary - dict{key} = [value1, value2, ....]
70 where = {'test_idx' : self.idx}
71 for i in iteration.select(self.db, where):
72 if self.__iterations.has_key(i.key):
73 self.__iterations[i.key].append(i.value)
74 else:
75 self.__iterations[i.key] = [i.value]
76 return self.__iterations
77
78
79 def kernel(self):
80 """
81 Caching function for kernels
82 """
83 if not self.__kernel:
84 where = {'kernel_idx' : self.kernel_idx}
85 self.__kernel = kernel.select(self.db, where)[0]
86 return self.__kernel
87
mbligh250300e2007-09-18 00:50:57 +000088
89class job:
90 def __init__(self, db, job_idx):
91 where = {'job_idx' : job_idx}
92 rows = db.select('tag, machine', 'jobs', where)
93 if not rows:
94 return None
95 (self.tag, self.machine) = rows[0]
96
mbligh8e1ab172007-09-13 17:29:56 +000097
mbligh16ae9262007-09-21 00:53:08 +000098class iteration:
99 @classmethod
100 def select(klass, db, where):
101 fields = ['iteration', 'attribute', 'value']
102 iterations = []
103 rows = db.select(','.join(fields), 'iteration_result', where)
104 for row in rows:
105 iterations.append(klass(*row))
106 return iterations
107
108
109 def __init__(self, iteration, key, value):
110 self.iteration = iteration
111 self.key = key
112 self.value = value
113
mbligh8e1ab172007-09-13 17:29:56 +0000114# class patch:
115# def __init__(self):
116# self.spec = None