def match_local(self, prefix, includes, excludes):
includes_pattern = r"<STR_LIT:|>".join([fnmatch.translate(x) for x in includes])<EOL>excludes_pattern = r"<STR_LIT:|>".join([fnmatch.translate(x) for x in excludes]) or r"<STR_LIT>"<EOL>matches = []<EOL>for root, dirs, files in os.walk(prefix, topdown=True):<EOL><INDENT>dirs[:] = [os.path.join(root, d) for d in dirs]<EOL>dirs[:] = [d for d in dirs if not re.match(excludes_pattern,<EOL>d.split(root)[<NUM_LIT:1>])]<EOL>files = [os.path.join(root, f) for f in files]<EOL>files = [os.path.join(root, f) for f in files<EOL>if not re.match(excludes_pattern, f)]<EOL>files = [os.path.join(root, f) for f in files<EOL>if re.match(includes_pattern, f.split(prefix)[<NUM_LIT:1>])]<EOL>for fname in files:<EOL><INDENT>matches.append(fname)<EOL><DEDENT><DEDENT>return matches<EOL>
Filters os.walk() with include and exclude patterns.
See: http://stackoverflow.com/a/5141829/93559