mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | import os, re |
| 3 | |
| 4 | valid_users = r'(apw|mbligh|andyw|korgtest)' |
| 5 | build_stock = re.compile('build generic stock (2\.\S+)') |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame^] | 6 | build_url = re.compile('build generic url \S*/linux-(2\.\d\.\d+(\.\d+)?(-rc\d+)?).tar') |
| 7 | valid_patch = re.compile('2\.\d\.\d+(\.\d+)?(-rc\d+)?(-(git|bk))\d+)?') |
| 8 | |
| 9 | |
| 10 | def shorten_patch(long): |
| 11 | short = basename(long) |
| 12 | short = re.sub(r'^patch-', '', short) |
| 13 | short = re.sub(r'\.(bz2|gz)$', '', short) |
| 14 | short = re.sub(r'\.patch$', '', short) |
| 15 | short = re.sub(r'\+', '_', short) |
| 16 | return short |
| 17 | |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 18 | |
| 19 | class job: |
| 20 | def __init__(self, topdir, key): |
| 21 | self.topdir = topdir |
| 22 | self.control = "%s/autobench.dat" % topdir |
| 23 | self.variables = {} |
| 24 | self.kernel = None |
| 25 | |
| 26 | if os.path.exists(self.control): |
| 27 | self.grope_datfile() |
| 28 | |
| 29 | |
| 30 | def grope_datfile(self): |
| 31 | variables = self.variables |
| 32 | for line in open(self.control, 'r').readlines(): |
| 33 | if line.startswith('+$'): |
| 34 | match = re.match(r'\+\$(\S+)\s+(\S?.*)', line) |
| 35 | variables[match.group(1)] = match.group(2) |
| 36 | if line.startswith('build '): |
| 37 | self.derive_build(line) |
| 38 | |
| 39 | if not re.match(valid_users, variables['username']): |
| 40 | raise "bad username - %s" % variables['username'] |
| 41 | |
| 42 | self.derive_patches() |
| 43 | self.derive_kernel() |
| 44 | |
| 45 | |
| 46 | def derive_build(self, raw_build): |
| 47 | # First to expand variables in the build line ... |
| 48 | self.build = '' |
| 49 | for element in re.split(r'(\$\w+)', raw_build): |
| 50 | if element.startswith('$'): |
| 51 | element = variables[element.lstrip('$')] |
| 52 | self.build += element |
| 53 | |
| 54 | |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame^] | 55 | def derive_patches(self): |
| 56 | self.patches_short = [] |
| 57 | self.patches_long = [] |
| 58 | m = re.search(r'-p (.*?) -') |
| 59 | if not m: |
| 60 | return |
| 61 | self.patches_long = m.group(1).split() |
| 62 | self.patches_short = [shorten_patch(p) for p in self.patches_long] |
| 63 | |
| 64 | |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 65 | # This is FOUL. we ought to be recording the data in kernel.build() |
| 66 | def derive_kernel(self): |
| 67 | # look for 'build generic stock' .... this is easy |
| 68 | match = build_stock.match(self.build) |
| 69 | if match: |
| 70 | self.kernel = match.group(1) |
| 71 | |
| 72 | # look for 'build generic url' .... this is harder, as we |
| 73 | # have to cope with patches that may set the kernel version |
mbligh | b85e6b0 | 2006-10-08 17:20:56 +0000 | [diff] [blame^] | 74 | match = build_url.match(self.build) |
| 75 | if match: |
| 76 | self.kernel = match.group(1) |
| 77 | |
| 78 | match = valid_patch.match(self.patches_short[0]) |
| 79 | if match: |
| 80 | self.kernel = p.group() |
mbligh | bb7b891 | 2006-10-08 03:59:02 +0000 | [diff] [blame] | 81 | |