blob: 270f077e3c00599eb3fbedd39f14368ea136c73c [file] [log] [blame]
mblighe9cf9d42007-08-31 08:56:00 +00001import sqlite, re
mblighd5c33db2006-10-08 21:34:16 +00002
3class db:
4 def __init__(self):
5 self.con = sqlite.connect('tko_db')
6 self.cur = self.con.cursor()
7
8
mbligh608c3252007-08-31 13:53:00 +00009 def select(self, fields, table, where_dict):
10 """\
11 select fields from table where {dictionary}
12 """
13 keys = [field + '=%s' for field in where_dict.keys()]
14 values = [where_dict[field] for field in where_dict.keys()]
15
16 where = 'and'.join(keys)
17 cmd = 'select %s from %s where %s' % (fields, table, where)
18 print cmd
19 print values
20 self.cur.execute(cmd, values)
mblighd5c33db2006-10-08 21:34:16 +000021 return self.cur.fetchall()
22
mbligh056d0d32006-10-08 22:31:10 +000023
mbligh608c3252007-08-31 13:53:00 +000024 def insert(self, table, data):
25 """\
26 'insert into table (keys) values (%s ... %s)', values
27
28 data:
29 dictionary of fields and data
30 """
31 fields = data.keys()
32 refs = ['%s' for field in fields]
33 values = [data[field] for field in fields]
34 cmd = 'insert into %s (%s) values (%s)' % \
35 (table, ','.join(fields), ','.join(refs))
36 print cmd
37 print values
38 self.cur.execute(cmd, values)
39 self.con.commit()
40
41
mbligh056d0d32006-10-08 22:31:10 +000042 def insert_job(self, tag, job):
mblighe9cf9d42007-08-31 08:56:00 +000043 # is kernel version in tree?
mbligh608c3252007-08-31 13:53:00 +000044 self.insert('jobs', {'tag':tag, 'machine':'UNKNOWN'})
45 job.index = self.find_job(tag)
46 for test in job.tests:
47 self.insert_test(job, test)
48
49 def insert_test(self, job, test):
50 # WE ARE MISSING KVERSION HERE!!!!
51 data = {'job_idx':job.index, 'test':test.testname,
52 'subdir':test.dir,
53 'status':test.status, 'reason':test.reason}
54 self.insert('tests', data)
mblighe9cf9d42007-08-31 08:56:00 +000055
56
mbligh608c3252007-08-31 13:53:00 +000057 def lookup_kernel_version(self, base, patches):
58 return self.select('kversion', 'kversions', {'base':base})[0]
mblighe9cf9d42007-08-31 08:56:00 +000059
60
mbligh608c3252007-08-31 13:53:00 +000061 def insert_kernel_version(self, base, patches):
62 self.insert('kversions', {'base': base})
mbligh056d0d32006-10-08 22:31:10 +000063
64
65 def find_job(self, tag):
mbligh608c3252007-08-31 13:53:00 +000066 rows = self.select('job_idx', 'jobs', {'tag': tag})
67 if rows:
68 return rows[0][0]
69 else:
70 return None