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 = ( |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 8 | # The major tarballs |
| 9 | r'linux-(2\.6\.\d+)\.tar\.bz2', |
| 10 | # Stable releases |
| 11 | r'patch-(2\.6\.\d+\.\d+)\.bz2', |
| 12 | # -rc releases |
| 13 | r'patch-(2\.6\.\d+-rc\d+)\.bz2', |
| 14 | # -git releases |
| 15 | r'patch-(2\.6\.\d+(-rc\d+)?-git\d+).bz2', |
| 16 | # -mm tree |
| 17 | r'(2\.6\.\d+(-rc\d+)?-mm\d+)\.bz2', |
| 18 | ) |
mbligh | 2c6e693 | 2006-10-07 22:08:47 +0000 | [diff] [blame] | 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): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 24 | def __init__(self): |
| 25 | self.__actions = [] |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 26 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 27 | def __re_scan(self, pattern, line): |
| 28 | """ |
| 29 | First check to see whether the pattern matches. |
| 30 | (eg. Does it match "linux-2.6.\d.tar.bz2" ?) |
| 31 | Then we strip out the actual trigger itself from that, |
| 32 | and return it. |
| 33 | (eg. return "2.6.\d") |
| 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 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +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 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 53 | # Call each of the actions and pass in the kernel list |
| 54 | for action in self.__actions: |
| 55 | action(triggers) |
mbligh | 31a8520 | 2007-09-26 17:18:45 +0000 | [diff] [blame] | 56 | |
| 57 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame^] | 58 | def add_action(self, func): |
| 59 | self.__actions.append(func) |