Package buildbot :: Package schedulers :: Module filter
[frames] | no frames]

Source Code for Module buildbot.schedulers.filter

 1  import re, types 
 2   
 3  from buildbot.util import ComparableMixin, NotABranch 
 4   
5 -class ChangeFilter(ComparableMixin):
6 7 # TODO: filter_fn will always be different. Does that mean that we always 8 # reconfigure schedulers? Is that a problem? 9 compare_attrs = ('filter_fn', 'checks') 10
11 - def __init__(self, 12 # gets a Change object, returns boolean 13 filter_fn=None, 14 # change attribute comparisons: exact match to PROJECT, member of 15 # list PROJECTS, regular expression match to PROJECT_RE, or 16 # PROJECT_FN returns True when called with the project; repository, 17 # branch, and so on are similar. Note that the regular expressions 18 # are anchored to the first character of the string. For convenience, 19 # a list can also be specified to the singular option (e.g,. PROJETS 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): # branch needs to be handled specially 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
47 - def filter_change(self, change):
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 (chg_val is None or 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
60 - def __repr__(self):
61 checks = [] 62 for (filt_list, filt_re, filt_fn, chg_attr) in self.checks: 63 if filt_list is not None and len(filt_list) == 1: 64 checks.append('%s == %s' % (chg_attr, filt_list[0])) 65 elif filt_list is not None: 66 checks.append('%s in %r' % (chg_attr, filt_list)) 67 if filt_re is not None : 68 checks.append('%s ~/%s/' % (chg_attr, filt_re)) 69 if filt_fn is not None : 70 checks.append('%s(%s)' % (filt_fn.__name__, chg_attr)) 71 72 return "<%s on %s>" % (self.__class__.__name__, ' and '.join(checks))
73