mbligh | c6b01ed | 2006-10-13 17:03:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | 26b992b | 2008-02-19 15:46:21 +0000 | [diff] [blame^] | 2 | import os, re, md5, sys, email.Message, smtplib, datetime |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 3 | client_bin = os.path.join(os.path.dirname(__file__), '../client/bin') |
| 4 | sys.path.insert(0, os.path.abspath(client_bin)) |
| 5 | from autotest_utils import read_keyval |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 6 | |
mbligh | b10a60f | 2007-10-17 00:03:32 +0000 | [diff] [blame] | 7 | user = re.compile(r'user(\s*)=') |
| 8 | label = re.compile(r'label(\s*)=') |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 9 | |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame] | 10 | debug = True |
| 11 | |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 12 | # XXX: these mail bits came almost verbatim from mirror/mirror and this should |
| 13 | # probably be refactored into another file and used by both. |
| 14 | def mail(from_address, to_addresses, cc_addresses, subject, message_text): |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 15 | # if passed a string for the to_addresses convert it to a tuple |
| 16 | if type(to_addresses) is str: |
| 17 | to_addresses = (to_addresses,) |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 18 | |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 19 | message = email.Message.Message() |
| 20 | message["To"] = ", ".join(to_addresses) |
| 21 | message["Cc"] = ", ".join(cc_addresses) |
| 22 | message["From"] = from_address |
| 23 | message["Subject"] = subject |
| 24 | message.set_payload(message_text) |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 25 | |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 26 | try: |
| 27 | sendmail(message.as_string()) |
| 28 | except SendmailException, e: |
| 29 | server = smtplib.SMTP("localhost") |
| 30 | server.sendmail(from_address, to_addresses, cc_addresses, message.as_string()) |
| 31 | server.quit() |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 32 | |
| 33 | |
| 34 | MAIL = "sendmail" |
| 35 | |
| 36 | class SendmailException(Exception): |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 37 | pass |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 38 | |
| 39 | def sendmail(message): |
mbligh | 08415d8 | 2007-11-24 19:23:34 +0000 | [diff] [blame] | 40 | """Send an email using sendmail""" |
| 41 | # open a pipe to the mail program and |
| 42 | # write the data to the pipe |
| 43 | p = os.popen("%s -t" % MAIL, 'w') |
| 44 | p.write(message) |
| 45 | exitcode = p.close() |
| 46 | if exitcode: |
| 47 | raise SendmailException("Exit code: %s" % exitcode) |
mbligh | 74fc046 | 2007-11-05 20:24:17 +0000 | [diff] [blame] | 48 | |
| 49 | # XXX: End of code from mirror/mirror |
| 50 | |
| 51 | |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 52 | def shorten_patch(long): |
mbligh | 340c968 | 2006-10-08 18:26:08 +0000 | [diff] [blame] | 53 | short = os.path.basename(long) |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame] | 54 | short = re.sub(r'^patch-', '', short) |
| 55 | short = re.sub(r'\.(bz2|gz)$', '', short) |
| 56 | short = re.sub(r'\.patch$', '', short) |
| 57 | short = re.sub(r'\+', '_', short) |
| 58 | return short |
| 59 | |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 60 | |
mbligh | 006f230 | 2007-09-13 20:46:46 +0000 | [diff] [blame] | 61 | def dprint(info): |
| 62 | if debug: |
| 63 | sys.stderr.write(str(info) + '\n') |
| 64 | |
| 65 | |
mbligh | 26b992b | 2008-02-19 15:46:21 +0000 | [diff] [blame^] | 66 | def keyval_timestamp(keyval, field): |
| 67 | val = keyval.get(field, None) |
| 68 | if val is not None: |
| 69 | val = datetime.datetime.fromtimestamp(int(val)) |
| 70 | return val |
| 71 | |
| 72 | |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 73 | class job: |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 74 | def __init__(self, dir): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 75 | self.dir = dir |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 76 | self.control = os.path.join(dir, "control") |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 77 | self.status = os.path.join(dir, "status.log") |
| 78 | if not os.path.exists(self.status): |
| 79 | self.status = os.path.join(dir, "status") |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 80 | self.variables = {} |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 81 | self.tests = [] |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 82 | self.kernel = None |
| 83 | |
mbligh | b10a60f | 2007-10-17 00:03:32 +0000 | [diff] [blame] | 84 | # Get the user + tag info from the keyval file. |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 85 | try: |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 86 | keyval = read_keyval(dir) |
| 87 | print keyval |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 88 | except: |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 89 | keyval = {} |
| 90 | self.user = keyval.get('user', None) |
| 91 | self.label = keyval.get('label', None) |
| 92 | self.machine = keyval.get('hostname', None) |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 93 | if self.machine: |
| 94 | assert ',' not in self.machine |
mbligh | 26b992b | 2008-02-19 15:46:21 +0000 | [diff] [blame^] | 95 | self.queued_time = keyval_timestamp(keyval, 'job_queued') |
| 96 | self.started_time = keyval_timestamp(keyval, 'job_started') |
| 97 | self.finished_time = keyval_timestamp(keyval, 'job_finished') |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 98 | self.machine_owner = keyval.get('owner', None) |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 99 | |
| 100 | if not self.machine: |
| 101 | self.get_machine() |
| 102 | |
| 103 | print 'MACHINE NAME: ' + self.machine |
| 104 | if not os.path.exists(self.status): |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 105 | return None |
| 106 | |
mbligh | 529f2f3 | 2007-08-30 11:22:50 +0000 | [diff] [blame] | 107 | self.grope_status() |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 108 | |
| 109 | |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 110 | def get_machine(self): |
| 111 | try: |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 112 | hostname = os.path.join(self.dir, "sysinfo/hostname") |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 113 | self.machine = open(hostname, 'r').readline().rstrip() |
| 114 | return |
| 115 | except: |
| 116 | pass |
| 117 | try: |
mbligh | 7a41a86 | 2007-11-30 17:44:24 +0000 | [diff] [blame] | 118 | uname = os.path.join(self.dir, "sysinfo/uname_-a") |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 119 | self.machine = open(uname, 'r').readline().split()[1] |
| 120 | return |
| 121 | except: |
| 122 | pass |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 123 | raise "Could not figure out machine name" |
mbligh | 532cb27 | 2007-11-26 18:54:20 +0000 | [diff] [blame] | 124 | |
| 125 | |
mbligh | d5c33db | 2006-10-08 21:34:16 +0000 | [diff] [blame] | 126 | def grope_status(self): |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 127 | """ |
| 128 | Note that what we're looking for here is level 1 groups |
| 129 | (ie end markers with 1 tab in front) |
| 130 | |
| 131 | For back-compatiblity, we also count level 0 groups that |
| 132 | are not job-level events, if there's no start/end job level |
| 133 | markers: "START ---- ----" |
| 134 | """ |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 135 | dprint('=====================================================') |
| 136 | dprint(self.dir) |
| 137 | dprint('=====================================================') |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 138 | self.kernel = kernel(self.dir) |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 139 | |
mbligh | 05d8121 | 2008-01-10 16:37:35 +0000 | [diff] [blame] | 140 | statuses = ['NOSTATUS', 'ERROR', 'ABORT', 'FAIL', 'WARN', |
| 141 | 'GOOD', 'ALERT'] |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 142 | reboot_inprogress = 0 # Saw reboot start and not finish |
mbligh | 9bcfef7 | 2008-02-12 20:55:34 +0000 | [diff] [blame] | 143 | boot_count = 0 |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 144 | alert_pending = None # Saw an ALERT for this test |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 145 | group_subdir = None |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 146 | sought_level = 0 # we log events at indent level 0 |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 147 | for line in open(self.status, 'r').readlines(): |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 148 | dprint('\nSTATUS: ' + line.rstrip()) |
| 149 | if not re.search(r'^\t*\S', line): |
| 150 | dprint('Continuation line, ignoring') |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 151 | continue # ignore continuation lines |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 152 | if re.search(r'^START\t----\t----', line): |
| 153 | sought_level = 1 |
| 154 | # we now log events at indent level 1 |
| 155 | dprint('Found job level start marker. Looking for level 1 groups now') |
| 156 | continue |
| 157 | indent = re.search('^(\t*)', line).group(0).count('\t') |
| 158 | line = line.strip() |
| 159 | if line.startswith('START\t'): |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 160 | group_subdir = None |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 161 | dprint('start line, ignoring') |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 162 | continue # ignore start lines |
| 163 | reason = None |
| 164 | if line.startswith('END'): |
| 165 | elements = line.split(None, 4)[1:] |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 166 | end = True |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 167 | else: |
| 168 | elements = line.split(None, 3) |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 169 | end = False |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 170 | elements.append(None) # in case no reason specified |
| 171 | (status, subdir, testname, reason) = elements[0:4] |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 172 | dprint('GROPE_STATUS: ' + str(elements[0:4])) |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 173 | if status == 'ALERT': |
| 174 | dprint('job level alert, recording') |
| 175 | alert_pending = reason |
| 176 | continue |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 177 | if testname == 'Autotest.install' and status == 'GOOD': |
| 178 | dprint('Sucessful autotest install, ignoring') |
mbligh | 59a479f | 2007-11-24 19:24:05 +0000 | [diff] [blame] | 179 | continue |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 180 | if testname == '----': |
| 181 | if status == 'ABORT' and not end: |
| 182 | testname = 'JOB' |
| 183 | else: |
| 184 | dprint('job level event, ignoring') |
| 185 | # This is a job level event, not a test |
| 186 | continue |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 187 | ################################################ |
| 188 | # REMOVE THIS SECTION ONCE OLD FORMAT JOBS ARE GONE |
| 189 | ################################################ |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 190 | if re.search(r'^(GOOD|FAIL|WARN) ', line): |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 191 | (status, testname, reason) = line.split(None, 2) |
| 192 | if testname.startswith('kernel.'): |
| 193 | subdir = 'build' |
| 194 | else: |
| 195 | subdir = testname |
| 196 | if testname.startswith('completed'): |
| 197 | raise 'testname is crap' |
| 198 | ################################################ |
| 199 | if subdir == '----': |
| 200 | subdir = None |
| 201 | if line.startswith('END'): |
| 202 | subdir = group_subdir |
mbligh | bafa6ef | 2008-01-10 16:36:52 +0000 | [diff] [blame] | 203 | if indent != sought_level and status != 'ABORT': |
| 204 | # we're in a block group |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 205 | if subdir: |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 206 | dprint('set group_subdir: %s' % subdir) |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 207 | group_subdir = subdir |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 208 | dprint('incorrect indent level %d != %d, ignoring' % (indent, sought_level)) |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 209 | continue |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 210 | if not re.search(r'^(boot$|kernel\.)', testname): |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 211 | # This is a real test |
| 212 | if subdir and subdir.count('.'): |
| 213 | # eg dbench.ext3 |
| 214 | testname = subdir |
mbligh | 0e21c87 | 2008-01-03 16:36:56 +0000 | [diff] [blame] | 215 | if testname == 'reboot.start': |
| 216 | dprint('reboot start event, ignoring') |
| 217 | reboot_inprogress = 1 |
| 218 | continue |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 219 | if testname == 'reboot.verify': |
mbligh | 9bcfef7 | 2008-02-12 20:55:34 +0000 | [diff] [blame] | 220 | testname = 'boot.%d' % boot_count |
mbligh | 0e21c87 | 2008-01-03 16:36:56 +0000 | [diff] [blame] | 221 | dprint('reboot verified') |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 222 | reboot_inprogress = 0 |
mbligh | 9bcfef7 | 2008-02-12 20:55:34 +0000 | [diff] [blame] | 223 | boot_count += 1 |
apw | 569f478 | 2007-12-13 19:32:53 +0000 | [diff] [blame] | 224 | if alert_pending: |
| 225 | status = 'ALERT' |
| 226 | reason = alert_pending |
| 227 | alert_pending = None |
mbligh | 05d8121 | 2008-01-10 16:37:35 +0000 | [diff] [blame] | 228 | if status in statuses: |
| 229 | dprint('Adding: %s\nSubdir:%s\nTestname:%s\n%s'% |
| 230 | (status, subdir, testname, reason)) |
| 231 | else: |
| 232 | dprint('WARNING: Invalid status code. Ignoring') |
| 233 | continue |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 234 | self.tests.append(test(subdir, testname, status, reason, self.kernel, self)) |
| 235 | dprint('') |
mbligh | 05d8121 | 2008-01-10 16:37:35 +0000 | [diff] [blame] | 236 | |
mbligh | 40d021b | 2007-12-03 17:35:51 +0000 | [diff] [blame] | 237 | if reboot_inprogress: |
| 238 | dprint('Adding: %s\nSubdir:%s\nTestname:%s\n%s' % |
| 239 | (status, subdir, testname, reason)) |
| 240 | self.tests.append(test('----', 'boot', 'ABORT', |
| 241 | 'machine did not return from reboot', |
| 242 | self.kernel, self)) |
| 243 | dprint('') |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 244 | |
| 245 | |
| 246 | class kernel: |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 247 | def __init__(self, topdir): |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 248 | self.base = 'UNKNOWN' |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 249 | self.patches = [] |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 250 | patch_hashes = [] |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 251 | # HACK. we don't have proper build tags in the status file yet |
| 252 | # so we hardcode build/ and do it at the start of the job |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 253 | build_log = os.path.join(topdir, 'build/debug/build_log') |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 254 | |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 255 | if os.path.exists(build_log): |
| 256 | for line in open(build_log, 'r'): |
mbligh | 049f5e6 | 2007-09-30 02:00:14 +0000 | [diff] [blame] | 257 | print line |
| 258 | (type, rest) = line.split(': ', 1) |
| 259 | words = rest.split() |
| 260 | if type == 'BASE': |
| 261 | self.base = words[0] |
| 262 | if type == 'PATCH': |
| 263 | print words |
| 264 | self.patches.append(patch(*words[0:])) |
| 265 | # patch_hashes.append(words[2]) |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 266 | else: |
| 267 | for sysinfo in ['sysinfo/reboot1', 'sysinfo']: |
| 268 | uname_file = os.path.join(topdir, sysinfo, 'uname_-a') |
| 269 | if not os.path.exists(uname_file): |
| 270 | continue |
| 271 | uname = open(uname_file, 'r').readline().split() |
| 272 | self.base = uname[2] |
mbligh | 215a166 | 2007-11-29 19:16:58 +0000 | [diff] [blame] | 273 | re.sub(r'-autotest$', '', self.base) |
mbligh | 9c39d15 | 2007-11-24 19:11:58 +0000 | [diff] [blame] | 274 | break |
| 275 | print 'kernel.__init__() found kernel version %s' % self.base |
mbligh | e8b37a9 | 2007-12-19 15:54:11 +0000 | [diff] [blame] | 276 | if self.base == 'UNKNOWN': |
| 277 | self.kernel_hash = 'UNKNOWN' |
| 278 | else: |
mbligh | 52f9744 | 2007-09-14 17:43:28 +0000 | [diff] [blame] | 279 | self.kernel_hash = self.get_kver_hash(self.base, patch_hashes) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 280 | |
| 281 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 282 | def get_kver_hash(self, base, patch_hashes): |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 283 | """\ |
| 284 | Calculate a hash representing the unique combination of |
| 285 | the kernel base version plus |
| 286 | """ |
| 287 | key_string = ','.join([base] + patch_hashes) |
| 288 | return md5.new(key_string).hexdigest() |
| 289 | |
| 290 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 291 | class patch: |
| 292 | def __init__(self, spec, reference=None, hash=None): |
| 293 | # NEITHER OF THE ABOVE SHOULD HAVE DEFAULTS!!!! HACK HACK |
| 294 | if not reference: |
| 295 | reference = spec |
| 296 | print 'PATCH::%s %s %s' % (spec, reference, hash) |
| 297 | self.spec = spec |
| 298 | self.reference = reference |
| 299 | self.hash = hash |
| 300 | |
| 301 | |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 302 | class test: |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 303 | def __init__(self, subdir, testname, status, reason, kernel, job): |
mbligh | de94094 | 2007-11-05 17:25:56 +0000 | [diff] [blame] | 304 | # NOTE: subdir may be none here for lines that aren't an |
| 305 | # actual test |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 306 | self.subdir = subdir |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 307 | self.testname = testname |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 308 | self.status = status |
| 309 | self.reason = reason |
mbligh | de94094 | 2007-11-05 17:25:56 +0000 | [diff] [blame] | 310 | self.version = None |
| 311 | self.keyval = None |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 312 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 313 | if subdir: |
mbligh | de94094 | 2007-11-05 17:25:56 +0000 | [diff] [blame] | 314 | keyval = os.path.join(job.dir, subdir, 'results/keyval') |
| 315 | if os.path.exists(keyval): |
| 316 | self.keyval = keyval |
| 317 | keyval2 = os.path.join(job.dir, subdir, 'keyval') |
| 318 | if os.path.exists(keyval2): |
| 319 | self.version = open(keyval2, 'r').readline().split('=')[1] |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 320 | else: |
| 321 | self.keyval = None |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 322 | self.iterations = [] |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 323 | self.kernel = kernel |
mbligh | 8e1ab17 | 2007-09-13 17:29:56 +0000 | [diff] [blame] | 324 | self.machine = job.machine |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 325 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 326 | dprint("PARSING TEST %s %s %s" % (subdir, testname, self.keyval)) |
mbligh | 994a23d | 2007-10-25 15:28:58 +0000 | [diff] [blame] | 327 | |
mbligh | de7335d | 2007-09-26 16:53:20 +0000 | [diff] [blame] | 328 | if not self.keyval: |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 329 | return |
| 330 | count = 1 |
| 331 | lines = [] |
| 332 | for line in open(self.keyval, 'r').readlines(): |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 333 | if not re.search('\S', line): # blank line |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 334 | self.iterations.append(iteration(count, lines)) |
| 335 | lines = [] |
| 336 | count += 1 |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 337 | else: |
| 338 | lines.append(line) |
| 339 | if lines: |
| 340 | self.iterations.append(iteration(count, lines)) |
| 341 | |
| 342 | |
| 343 | class iteration: |
| 344 | def __init__(self, index, lines): |
| 345 | self.index = index |
| 346 | self.keyval = {} |
| 347 | |
mbligh | 2bd4887 | 2007-09-20 18:32:25 +0000 | [diff] [blame] | 348 | dprint("ADDING ITERATION %d" % index) |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 349 | for line in lines: |
mbligh | 4921b98 | 2007-12-03 17:47:45 +0000 | [diff] [blame] | 350 | line = line.rstrip(); |
mbligh | e9cf9d4 | 2007-08-31 08:56:00 +0000 | [diff] [blame] | 351 | (key, value) = line.split('=', 1) |
| 352 | self.keyval[key] = value |