mbligh | c6b01ed | 2006-10-13 17:03:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 2 | import os, re |
| 3 | |
| 4 | # Given a file full of rsync output, scan through it for things that look like |
| 5 | # legitimate releases. Return the simplified triggers for each of those files. |
| 6 | |
| 7 | matches = ( |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 8 | # The major tarballs |
mbligh | 5dfc84e | 2006-10-07 22:28:31 +0000 | [diff] [blame] | 9 | r'linux-(2\.6\.\d+)\.tar\.bz2', |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 10 | # Stable releases |
mbligh | 5dfc84e | 2006-10-07 22:28:31 +0000 | [diff] [blame] | 11 | r'patch-(2\.6\.\d+\.\d+)\.bz2', |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 12 | # -rc releases |
mbligh | 5dfc84e | 2006-10-07 22:28:31 +0000 | [diff] [blame] | 13 | r'patch-(2\.6\.\d+-rc\d+)\.bz2', |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 14 | # -git releases |
| 15 | r'patch-(2\.6\.\d+(-rc\d+)?-git\d+).bz2', |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 16 | # -mm tree |
mbligh | 5dfc84e | 2006-10-07 22:28:31 +0000 | [diff] [blame] | 17 | r'(2\.6\.\d+(-rc\d+)?-mm\d+)\.bz2', |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 18 | ) |
| 19 | |
mbligh | 5dfc84e | 2006-10-07 22:28:31 +0000 | [diff] [blame] | 20 | compiled_matches = [re.compile(r) for r in matches] |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 21 | |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 22 | |
| 23 | class Trigger(object): |
| 24 | def __init__(self): |
| 25 | self.__actions = [] |
| 26 | |
| 27 | def __re_scan(self, pattern, line): |
| 28 | """ |
| 29 | First check to see whether the pattern matches. |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 30 | (eg. Does it match "linux-2.6.\d.tar.bz2" ?) |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 31 | Then we strip out the actual trigger itself from that, |
| 32 | and return it. |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 33 | (eg. return "2.6.\d") |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 34 | Note that the pattern uses match, |
| 35 | so you need the whole filename |
| 36 | """ |
| 37 | match = pattern.match(line) |
| 38 | if match: |
| 39 | return match.group(1) |
| 40 | else: |
| 41 | return None |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 42 | |
mbligh | 5dfc84e | 2006-10-07 22:28:31 +0000 | [diff] [blame] | 43 | |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 44 | def scan(self, input_file): |
| 45 | triggers = [] |
| 46 | for line in open(input_file, 'r').readlines(): |
| 47 | for pattern in compiled_matches: |
| 48 | filename = os.path.basename(line) |
| 49 | t = self.__re_scan(pattern, filename) |
| 50 | if t: |
| 51 | triggers.append(t) |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 52 | |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 53 | # Call each of the actions and pass in the kernel list |
| 54 | for action in self.__actions: |
| 55 | action(triggers) |
| 56 | |
| 57 | |
| 58 | def add_action(self, func): |
| 59 | self.__actions.append(func) |