mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 1 | import re, os, sys, types |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 2 | |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 3 | class db_sql: |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 4 | def __init__(self, debug = False, autocommit=True): |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 5 | self.debug = debug |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 6 | self.autocommit = autocommit |
mbligh | a218d11 | 2007-10-03 20:15:09 +0000 | [diff] [blame] | 7 | |
| 8 | path = os.path.dirname(os.path.abspath(sys.argv[0])) |
mbligh | b32cd43 | 2007-09-25 18:20:04 +0000 | [diff] [blame] | 9 | try: |
mbligh | a218d11 | 2007-10-03 20:15:09 +0000 | [diff] [blame] | 10 | file = os.path.join(path, '.database') |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 11 | db_prefs = open(file, 'r') |
mbligh | 728ff0a | 2007-09-27 17:05:12 +0000 | [diff] [blame] | 12 | host = db_prefs.readline().rstrip() |
| 13 | database = db_prefs.readline().rstrip() |
| 14 | except: |
| 15 | host = 'localhost' |
| 16 | database = 'tko' |
| 17 | |
| 18 | try: |
mbligh | a218d11 | 2007-10-03 20:15:09 +0000 | [diff] [blame] | 19 | file = os.path.join(path, '.priv_login') |
| 20 | login = open(file, 'r') |
mbligh | b32cd43 | 2007-09-25 18:20:04 +0000 | [diff] [blame] | 21 | user = login.readline().rstrip() |
| 22 | password = login.readline().rstrip() |
mbligh | 95fca57 | 2007-09-27 17:11:00 +0000 | [diff] [blame] | 23 | except: |
| 24 | try: |
mbligh | a218d11 | 2007-10-03 20:15:09 +0000 | [diff] [blame] | 25 | file = os.path.join(path, '.unpriv_login') |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 26 | login = open(file, 'r') |
mbligh | 95fca57 | 2007-09-27 17:11:00 +0000 | [diff] [blame] | 27 | user = login.readline().rstrip() |
| 28 | password = login.readline().rstrip() |
| 29 | except: |
| 30 | user = 'nobody' |
| 31 | password = '' |
mbligh | b32cd43 | 2007-09-25 18:20:04 +0000 | [diff] [blame] | 32 | |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 33 | self.con = self.connect(host, database, user, password) |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 34 | self.cur = self.con.cursor() |
| 35 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 36 | # if not present, insert statuses |
| 37 | self.status_idx = {} |
| 38 | self.status_word = {} |
mbligh | c82f246 | 2007-10-02 19:19:17 +0000 | [diff] [blame] | 39 | status_rows = self.select('status_idx, word', 'status', None) |
| 40 | for s in status_rows: |
mbligh | 9789445 | 2007-10-05 15:10:33 +0000 | [diff] [blame] | 41 | self.status_idx[s[1]] = s[0] |
mbligh | c82f246 | 2007-10-02 19:19:17 +0000 | [diff] [blame] | 42 | self.status_word[s[0]] = s[1] |
mbligh | 048e1c9 | 2007-10-07 00:10:33 +0000 | [diff] [blame] | 43 | |
| 44 | dir = os.path.abspath(os.path.dirname(sys.argv[0])) |
| 45 | machine_map = os.path.join(dir, 'machines') |
| 46 | if os.path.exists(machine_map): |
| 47 | self.machine_map = machine_map |
mbligh | ba9c54c | 2007-10-26 16:41:26 +0000 | [diff] [blame] | 48 | else: |
| 49 | self.machine_map = None |
mbligh | 048e1c9 | 2007-10-07 00:10:33 +0000 | [diff] [blame] | 50 | self.machine_group = {} |
| 51 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 52 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 53 | def dprint(self, value): |
| 54 | if self.debug: |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame^] | 55 | sys.stdout.write('SQL: ' + str(value) + '\n') |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 56 | |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 57 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 58 | def commit(self): |
| 59 | self.con.commit() |
| 60 | |
| 61 | |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame^] | 62 | def select(self, fields, table, where, wherein={}, distinct = False, |
| 63 | group_by = None): |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 64 | """\ |
| 65 | select fields from table where {dictionary} |
| 66 | """ |
mbligh | 31d29c4 | 2007-09-27 00:51:33 +0000 | [diff] [blame] | 67 | cmd = ['select'] |
| 68 | if distinct: |
| 69 | cmd.append('distinct') |
| 70 | cmd += [fields, 'from', table] |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 71 | |
mbligh | 31d29c4 | 2007-09-27 00:51:33 +0000 | [diff] [blame] | 72 | values = [] |
mbligh | 414c69e | 2007-10-05 15:13:06 +0000 | [diff] [blame] | 73 | if where and isinstance(where, types.DictionaryType): |
mbligh | 53d1425 | 2007-09-12 16:33:14 +0000 | [diff] [blame] | 74 | keys = [field + '=%s' for field in where.keys()] |
| 75 | values = [where[field] for field in where.keys()] |
| 76 | |
mbligh | 31d29c4 | 2007-09-27 00:51:33 +0000 | [diff] [blame] | 77 | cmd.append(' where ' + ' and '.join(keys)) |
mbligh | 414c69e | 2007-10-05 15:13:06 +0000 | [diff] [blame] | 78 | elif where and isinstance(where, types.StringTypes): |
| 79 | cmd.append(' where ' + where) |
mbligh | 53d1425 | 2007-09-12 16:33:14 +0000 | [diff] [blame] | 80 | |
mbligh | 85952b4 | 2007-12-07 16:28:33 +0000 | [diff] [blame] | 81 | if wherein and isinstance(wherein, types.DictionaryType): |
| 82 | keys_in = [] |
| 83 | for field_in in wherein.keys(): |
| 84 | keys_in += [field_in + ' in (' + ','.join(wherein[field_in])+') '] |
| 85 | |
| 86 | cmd.append(' and '+' and '.join(keys_in)) |
mbligh | 83f63a0 | 2007-12-12 19:13:04 +0000 | [diff] [blame^] | 87 | if group_by: |
| 88 | cmd.append(' GROUP BY ' + group_by) |
| 89 | |
| 90 | self.dprint('%s %s' % (' '.join(cmd), values)) |
mbligh | 31d29c4 | 2007-09-27 00:51:33 +0000 | [diff] [blame] | 91 | self.cur.execute(' '.join(cmd), values) |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 92 | return self.cur.fetchall() |
| 93 | |
mbligh | 056d0d3 | 2006-10-08 22:31:10 +0000 | [diff] [blame] | 94 | |
mbligh | 414c69e | 2007-10-05 15:13:06 +0000 | [diff] [blame] | 95 | def select_sql(self, fields, table, sql, values): |
| 96 | """\ |
| 97 | select fields from table "sql" |
| 98 | """ |
| 99 | cmd = 'select %s from %s %s' % (fields, table, sql) |
| 100 | self.dprint(cmd) |
| 101 | self.cur.execute(cmd, values) |
| 102 | return self.cur.fetchall() |
| 103 | |
| 104 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 105 | def insert(self, table, data, commit = None): |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 106 | """\ |
| 107 | 'insert into table (keys) values (%s ... %s)', values |
| 108 | |
| 109 | data: |
| 110 | dictionary of fields and data |
| 111 | """ |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 112 | if commit == None: |
| 113 | commit = self.autocommit |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 114 | fields = data.keys() |
| 115 | refs = ['%s' for field in fields] |
| 116 | values = [data[field] for field in fields] |
| 117 | cmd = 'insert into %s (%s) values (%s)' % \ |
| 118 | (table, ','.join(fields), ','.join(refs)) |
mbligh | 53d1425 | 2007-09-12 16:33:14 +0000 | [diff] [blame] | 119 | |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 120 | self.dprint('%s %s' % (cmd,values)) |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 121 | self.cur.execute(cmd, values) |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 122 | if commit: |
| 123 | self.con.commit() |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 124 | |
| 125 | |
mbligh | 96b9a5a | 2007-11-24 19:32:20 +0000 | [diff] [blame] | 126 | def delete(self, table, where, commit = None): |
| 127 | cmd = ['delete from', table] |
| 128 | if commit == None: |
| 129 | commit = self.autocommit |
| 130 | if where and isinstance(where, types.DictionaryType): |
| 131 | keys = [field + '=%s' for field in where.keys()] |
| 132 | values = [where[field] for field in where.keys()] |
| 133 | cmd += ['where', ' and '.join(keys)] |
| 134 | self.dprint('%s %s' % (' '.join(cmd),values)) |
| 135 | self.cur.execute(' '.join(cmd), values) |
| 136 | if commit: |
| 137 | self.con.commit() |
| 138 | |
| 139 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 140 | def update(self, table, data, where, commit = None): |
mbligh | 414c69e | 2007-10-05 15:13:06 +0000 | [diff] [blame] | 141 | """\ |
| 142 | 'update table set data values (%s ... %s) where ...' |
| 143 | |
| 144 | data: |
| 145 | dictionary of fields and data |
| 146 | """ |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 147 | if commit == None: |
| 148 | commit = self.autocommit |
mbligh | 414c69e | 2007-10-05 15:13:06 +0000 | [diff] [blame] | 149 | cmd = 'update %s ' % table |
| 150 | fields = data.keys() |
| 151 | data_refs = [field + '=%s' for field in fields] |
| 152 | data_values = [data[field] for field in fields] |
| 153 | cmd += ' set ' + ' and '.join(data_refs) |
| 154 | |
| 155 | where_keys = [field + '=%s' for field in where.keys()] |
| 156 | where_values = [where[field] for field in where.keys()] |
| 157 | cmd += ' where ' + ' and '.join(where_keys) |
| 158 | |
| 159 | print '%s %s' % (cmd, data_values + where_values) |
| 160 | self.cur.execute(cmd, data_values + where_values) |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 161 | if commit: |
| 162 | self.con.commit() |
mbligh | 414c69e | 2007-10-05 15:13:06 +0000 | [diff] [blame] | 163 | |
| 164 | |
mbligh | 96b9a5a | 2007-11-24 19:32:20 +0000 | [diff] [blame] | 165 | def delete_job(self, tag, commit = None): |
| 166 | job_idx = self.find_job(tag) |
| 167 | for test_idx in self.find_tests(job_idx): |
| 168 | where = {'test_idx' : test_idx} |
| 169 | self.delete('iteration_result', where) |
| 170 | self.delete('test_attributes', where) |
| 171 | where = {'job_idx' : job_idx} |
| 172 | self.delete('tests', where) |
| 173 | self.delete('jobs', where) |
| 174 | |
| 175 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 176 | def insert_job(self, tag, job, commit = None): |
mbligh | 2aaeb67 | 2007-10-01 14:54:18 +0000 | [diff] [blame] | 177 | job.machine_idx = self.lookup_machine(job.machine) |
| 178 | if not job.machine_idx: |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 179 | job.machine_idx = self.insert_machine(job, |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 180 | commit=commit) |
mbligh | b10a60f | 2007-10-17 00:03:32 +0000 | [diff] [blame] | 181 | self.insert('jobs', {'tag':tag, |
| 182 | 'label': job.label, |
mbligh | 05067a3 | 2007-12-03 17:48:04 +0000 | [diff] [blame] | 183 | 'username': job.user, |
mbligh | b10a60f | 2007-10-17 00:03:32 +0000 | [diff] [blame] | 184 | 'machine_idx':job.machine_idx}, |
| 185 | commit=commit) |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 186 | job.index = self.find_job(tag) |
| 187 | for test in job.tests: |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 188 | self.insert_test(job, test, commit=commit) |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 189 | |
mbligh | 96b9a5a | 2007-11-24 19:32:20 +0000 | [diff] [blame] | 190 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 191 | def insert_test(self, job, test, commit = None): |
| 192 | kver = self.insert_kernel(test.kernel, commit=commit) |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 193 | data = {'job_idx':job.index, 'test':test.testname, |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 194 | 'subdir':test.subdir, 'kernel_idx':kver, |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 195 | 'status':self.status_idx[test.status], |
mbligh | 2aaeb67 | 2007-10-01 14:54:18 +0000 | [diff] [blame] | 196 | 'reason':test.reason, 'machine_idx':job.machine_idx } |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 197 | self.insert('tests', data, commit=commit) |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 198 | test_idx = self.find_test(job.index, test.subdir) |
| 199 | data = { 'test_idx':test_idx } |
| 200 | |
| 201 | for i in test.iterations: |
| 202 | data['iteration'] = i.index |
| 203 | for key in i.keyval: |
| 204 | data['attribute'] = key |
| 205 | data['value'] = i.keyval[key] |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 206 | self.insert('iteration_result', |
| 207 | data, |
| 208 | commit=commit) |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 209 | data = {'test_idx':test_idx, 'attribute':'version', 'value':test.version} |
| 210 | self.insert('test_attributes', data, commit=commit) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 211 | |
| 212 | |
mbligh | 048e1c9 | 2007-10-07 00:10:33 +0000 | [diff] [blame] | 213 | def read_machine_map(self): |
| 214 | self.machine_group = {} |
| 215 | for line in open(self.machine_map, 'r').readlines(): |
| 216 | (machine, group) = line.split() |
| 217 | self.machine_group[machine] = group |
| 218 | |
| 219 | |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 220 | def insert_machine(self, job, group = None, commit = None): |
| 221 | hostname = job.machine |
mbligh | 048e1c9 | 2007-10-07 00:10:33 +0000 | [diff] [blame] | 222 | if self.machine_map and not self.machine_group: |
| 223 | self.read_machine_map() |
| 224 | |
| 225 | if not group: |
| 226 | group = self.machine_group.get(hostname, hostname) |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 227 | if group == hostname and job.machine_owner: |
| 228 | group = job.machine_owner + '/' + hostname |
| 229 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 230 | self.insert('machines', |
| 231 | { 'hostname' : hostname , |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 232 | 'machine_group' : group , |
| 233 | 'owner' : job.machine_owner }, |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 234 | commit=commit) |
mbligh | 2aaeb67 | 2007-10-01 14:54:18 +0000 | [diff] [blame] | 235 | return self.lookup_machine(hostname) |
| 236 | |
| 237 | |
| 238 | def lookup_machine(self, hostname): |
| 239 | where = { 'hostname' : hostname } |
| 240 | rows = self.select('machine_idx', 'machines', where) |
| 241 | if rows: |
| 242 | return rows[0][0] |
| 243 | else: |
| 244 | return None |
| 245 | |
| 246 | |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 247 | def lookup_kernel(self, kernel): |
| 248 | rows = self.select('kernel_idx', 'kernels', |
mbligh | 048e1c9 | 2007-10-07 00:10:33 +0000 | [diff] [blame] | 249 | {'kernel_hash':kernel.kernel_hash}) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 250 | if rows: |
| 251 | return rows[0][0] |
| 252 | else: |
| 253 | return None |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 254 | |
| 255 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 256 | def insert_kernel(self, kernel, commit = None): |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 257 | kver = self.lookup_kernel(kernel) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 258 | if kver: |
| 259 | return kver |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 260 | self.insert('kernels', |
| 261 | {'base':kernel.base, |
| 262 | 'kernel_hash':kernel.kernel_hash, |
| 263 | 'printable':kernel.base}, |
| 264 | commit=commit) |
mbligh | 9bb92fe | 2007-09-12 15:54:23 +0000 | [diff] [blame] | 265 | # WARNING - incorrectly shoving base into printable here. |
| 266 | kver = self.lookup_kernel(kernel) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 267 | for patch in kernel.patches: |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 268 | self.insert_patch(kver, patch, commit=commit) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 269 | return kver |
| 270 | |
| 271 | |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 272 | def insert_patch(self, kver, patch, commit = None): |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 273 | print patch.reference |
| 274 | name = os.path.basename(patch.reference)[:80] |
mbligh | 432bad4 | 2007-10-09 19:56:07 +0000 | [diff] [blame] | 275 | self.insert('patches', |
| 276 | {'kernel_idx': kver, |
| 277 | 'name':name, |
| 278 | 'url':patch.reference, |
| 279 | 'hash':patch.hash}, |
| 280 | commit=commit) |
mbligh | 056d0d3 | 2006-10-08 22:31:10 +0000 | [diff] [blame] | 281 | |
mbligh | 048e1c9 | 2007-10-07 00:10:33 +0000 | [diff] [blame] | 282 | |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 283 | def find_test(self, job_idx, subdir): |
| 284 | where = { 'job_idx':job_idx , 'subdir':subdir } |
| 285 | rows = self.select('test_idx', 'tests', where) |
| 286 | if rows: |
| 287 | return rows[0][0] |
| 288 | else: |
| 289 | return None |
| 290 | |
mbligh | 056d0d3 | 2006-10-08 22:31:10 +0000 | [diff] [blame] | 291 | |
mbligh | 96b9a5a | 2007-11-24 19:32:20 +0000 | [diff] [blame] | 292 | def find_tests(self, job_idx): |
| 293 | where = { 'job_idx':job_idx } |
| 294 | rows = self.select('test_idx', 'tests', where) |
| 295 | if rows: |
| 296 | return [row[0] for row in rows] |
| 297 | else: |
mbligh | 2e57e7b | 2007-11-29 16:10:50 +0000 | [diff] [blame] | 298 | return [] |
mbligh | 96b9a5a | 2007-11-24 19:32:20 +0000 | [diff] [blame] | 299 | |
| 300 | |
mbligh | 056d0d3 | 2006-10-08 22:31:10 +0000 | [diff] [blame] | 301 | def find_job(self, tag): |
mbligh | 608c325 | 2007-08-31 13:53:00 +0000 | [diff] [blame] | 302 | rows = self.select('job_idx', 'jobs', {'tag': tag}) |
| 303 | if rows: |
| 304 | return rows[0][0] |
| 305 | else: |
| 306 | return None |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 307 | |
| 308 | |
| 309 | # Use a class method as a class factory, generating a relevant database object. |
| 310 | def db(*args, **dargs): |
| 311 | path = os.path.dirname(os.path.abspath(sys.argv[0])) |
mbligh | a044e56 | 2007-12-07 16:26:13 +0000 | [diff] [blame] | 312 | db_type = None |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 313 | try: |
mbligh | a044e56 | 2007-12-07 16:26:13 +0000 | [diff] [blame] | 314 | db_file = os.path.join(path, '.database') |
| 315 | db_prefs = open(db_file, 'r') |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 316 | host = db_prefs.readline().rstrip() |
| 317 | database = db_prefs.readline().rstrip() |
mbligh | a044e56 | 2007-12-07 16:26:13 +0000 | [diff] [blame] | 318 | db_type = db_prefs.readline().rstrip() |
| 319 | except: |
| 320 | pass |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 321 | |
mbligh | a044e56 | 2007-12-07 16:26:13 +0000 | [diff] [blame] | 322 | if not db_type: |
| 323 | db_type = 'mysql' |
| 324 | |
| 325 | db_type = 'db_' + db_type |
| 326 | exec 'import %s; db = %s.%s(*args, **dargs)' % (db_type, db_type, db_type) |
mbligh | af25f06 | 2007-12-03 17:48:35 +0000 | [diff] [blame] | 327 | |
| 328 | return db |