blob: 562ec0525c5a396c8c314a9125efc30760253bdd [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 = (
jadmanski0afbb632008-06-06 21:10:57 +00008 # 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 )
mbligh2c6e6932006-10-07 22:08:47 +000019
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):
jadmanski0afbb632008-06-06 21:10:57 +000024 def __init__(self):
25 self.__actions = []
mbligh31a85202007-09-26 17:18:45 +000026
jadmanski0afbb632008-06-06 21:10:57 +000027 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
mbligh2c6e6932006-10-07 22:08:47 +000042
mbligh5dfc84e2006-10-07 22:28:31 +000043
jadmanski0afbb632008-06-06 21:10:57 +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
jadmanski0afbb632008-06-06 21:10:57 +000053 # Call each of the actions and pass in the kernel list
54 for action in self.__actions:
55 action(triggers)
mbligh31a85202007-09-26 17:18:45 +000056
57
jadmanski0afbb632008-06-06 21:10:57 +000058 def add_action(self, func):
59 self.__actions.append(func)