blob: cccef7c78e2c8a925b026c6fcff8950740921486 [file] [log] [blame]
mblighc6b01ed2006-10-13 17:03:26 +00001#!/usr/bin/python
mbligh2c6e6932006-10-07 22:08:47 +00002import 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
7matches = (
mbligh31a85202007-09-26 17:18:45 +00008 # The major tarballs
mbligh5dfc84e2006-10-07 22:28:31 +00009 r'linux-(2\.6\.\d+)\.tar\.bz2',
mbligh31a85202007-09-26 17:18:45 +000010 # Stable releases
mbligh5dfc84e2006-10-07 22:28:31 +000011 r'patch-(2\.6\.\d+\.\d+)\.bz2',
mbligh31a85202007-09-26 17:18:45 +000012 # -rc releases
mbligh5dfc84e2006-10-07 22:28:31 +000013 r'patch-(2\.6\.\d+-rc\d+)\.bz2',
mbligh31a85202007-09-26 17:18:45 +000014 # -git releases
15 r'patch-(2\.6\.\d+(-rc\d+)?-git\d+).bz2',
mbligh2c6e6932006-10-07 22:08:47 +000016 # -mm tree
mbligh5dfc84e2006-10-07 22:28:31 +000017 r'(2\.6\.\d+(-rc\d+)?-mm\d+)\.bz2',
mbligh2c6e6932006-10-07 22:08:47 +000018 )
19
mbligh5dfc84e2006-10-07 22:28:31 +000020compiled_matches = [re.compile(r) for r in matches]
mbligh2c6e6932006-10-07 22:08:47 +000021
mbligh31a85202007-09-26 17:18:45 +000022
23class 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.
mbligh2c6e6932006-10-07 22:08:47 +000030 (eg. Does it match "linux-2.6.\d.tar.bz2" ?)
mbligh31a85202007-09-26 17:18:45 +000031 Then we strip out the actual trigger itself from that,
32 and return it.
mbligh2c6e6932006-10-07 22:08:47 +000033 (eg. return "2.6.\d")
mbligh31a85202007-09-26 17:18:45 +000034 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
mbligh2c6e6932006-10-07 22:08:47 +000042
mbligh5dfc84e2006-10-07 22:28:31 +000043
mbligh31a85202007-09-26 17:18:45 +000044 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)
mbligh2c6e6932006-10-07 22:08:47 +000052
mbligh31a85202007-09-26 17:18:45 +000053 # 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)