1 import re, types
2
3 from buildbot.util import ComparableMixin, NotABranch
4
6
7
8
9 compare_attrs = ('filter_fn', 'checks')
10
11 - def __init__(self,
12
13 filter_fn=None,
14
15
16
17
18
19
20 project=None, project_re=None, project_fn=None,
21 repository=None, repository_re=None, repository_fn=None,
22 branch=NotABranch, branch_re=None, branch_fn=None,
23 category=None, category_re=None, category_fn=None):
24 def mklist(x):
25 if x is not None and type(x) is not types.ListType:
26 return [ x ]
27 return x
28 def mklist_br(x):
29 if x is NotABranch:
30 return None
31 if type(x) is not types.ListType:
32 return [ x ]
33 return x
34 def mkre(r):
35 if r is not None and not hasattr(r, 'match'):
36 r = re.compile(r)
37 return r
38
39 self.filter_fn = filter_fn
40 self.checks = [
41 (mklist(project), mkre(project_re), project_fn, "project"),
42 (mklist(repository), mkre(repository_re), repository_fn, "repository"),
43 (mklist_br(branch), mkre(branch_re), branch_fn, "branch"),
44 (mklist(category), mkre(category_re), category_fn, "category"),
45 ]
46
48 if self.filter_fn is not None and not self.filter_fn(change):
49 return False
50 for (filt_list, filt_re, filt_fn, chg_attr) in self.checks:
51 chg_val = getattr(change, chg_attr, '')
52 if filt_list is not None and chg_val not in filt_list:
53 return False
54 if filt_re is not None and not filt_re.match(chg_val):
55 return False
56 if filt_fn is not None and not filt_fn(chg_val):
57 return False
58 return True
59