[Buildbot-devel] Useful filtering sample

Dobes Vandermeer dobesv at gmail.com
Mon Oct 31 20:14:42 UTC 2005

I thought it might help people to have an example on how to filter
files by name.  I suppose ideally this would be built into Scheduler -
e.g. by passing a 'fileNameFilters' keyword parameter that then calls
this and sets fileIsImportant.  I'm using perforce syntax so that I
can cut'n'paste from the perforce clientspec, and its a fairly easy
and useful format compared to other wildcards for this purpose.

def mkcheckfunc(p4paths):
    """ Pass in a list of p4-style wildcards.  Use * to select a
wildcard within a folder,
        or ... to select a wildcard that spans all subfolders.  Prefix
a string with a - to
        exclude matching files.  Also you can use any regular
expression syntax except .,
        which is escaped.  The result is a callable that can be passed
as the fileIsImportant
        keyword to Scheduler().
    import re
    def mkregexStr(p4paths):
        return '|'.join([re.compile(r'\.(?!\*)').sub('\\.',
p4path.replace('*', r'[^/\\]*').replace('...','.*')) for p4path in
    def checkChange(change, regex):
        for f in change.files:
            if regex.match(f): return True
    regexStr = mkregexStr([p for p in p4paths if not p.startswith('-')])
    excludes = [p[1:] for p in p4paths if p.startswith('-')]
    if excludes:
		regexStr = '(?!'+mkregexStr(excludes)+')(?:'+regexStr+')'
    regex = re.compile(regexStr, re.IGNORECASE)
    #print 'regex', regexStr
    return lambda change, regex=regex: checkChange(change, regex)

winBuildFiles = mkcheckfunc([

c['schedulers'].append(Scheduler('winbuild', None, 10, ['slave1',
'slave2'], fileIsImportant=winBuildFiles))

More information about the devel mailing list