1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import re, types
17
18 from buildbot.util import ComparableMixin, NotABranch
19
21
22
23
24 compare_attrs = ('filter_fn', 'checks')
25
26 - def __init__(self,
27
28 filter_fn=None,
29
30
31
32
33
34
35 project=None, project_re=None, project_fn=None,
36 repository=None, repository_re=None, repository_fn=None,
37 branch=NotABranch, branch_re=None, branch_fn=None,
38 category=None, category_re=None, category_fn=None):
39 def mklist(x):
40 if x is not None and type(x) is not types.ListType:
41 return [ x ]
42 return x
43 def mklist_br(x):
44 if x is NotABranch:
45 return None
46 if type(x) is not types.ListType:
47 return [ x ]
48 return x
49 def mkre(r):
50 if r is not None and not hasattr(r, 'match'):
51 r = re.compile(r)
52 return r
53
54 self.filter_fn = filter_fn
55 self.checks = [
56 (mklist(project), mkre(project_re), project_fn, "project"),
57 (mklist(repository), mkre(repository_re), repository_fn, "repository"),
58 (mklist_br(branch), mkre(branch_re), branch_fn, "branch"),
59 (mklist(category), mkre(category_re), category_fn, "category"),
60 ]
61
63 if self.filter_fn is not None and not self.filter_fn(change):
64 return False
65 for (filt_list, filt_re, filt_fn, chg_attr) in self.checks:
66 chg_val = getattr(change, chg_attr, '')
67 if filt_list is not None and chg_val not in filt_list:
68 return False
69 if filt_re is not None and (chg_val is None or not filt_re.match(chg_val)):
70 return False
71 if filt_fn is not None and not filt_fn(chg_val):
72 return False
73 return True
74
76 checks = []
77 for (filt_list, filt_re, filt_fn, chg_attr) in self.checks:
78 if filt_list is not None and len(filt_list) == 1:
79 checks.append('%s == %s' % (chg_attr, filt_list[0]))
80 elif filt_list is not None:
81 checks.append('%s in %r' % (chg_attr, filt_list))
82 if filt_re is not None :
83 checks.append('%s ~/%s/' % (chg_attr, filt_re))
84 if filt_fn is not None :
85 checks.append('%s(%s)' % (filt_fn.__name__, chg_attr))
86
87 return "<%s on %s>" % (self.__class__.__name__, ' and '.join(checks))
88