From 42afb74959d043efa3d30873703736d3552aebfa Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 13 Jun 2010 21:46:35 -0400 Subject: The 'source' option is a list of directories or packages to limit coverage's attention. --- coverage/files.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index 5690679..d74b4d7 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -1,6 +1,6 @@ """File wrangling.""" -import os, sys +import fnmatch, os, sys class FileLocator(object): """Understand how filenames work.""" @@ -76,3 +76,37 @@ class FileLocator(object): data = data.decode('utf8') # TODO: How to do this properly? return data return None + + +class TreeMatcher(object): + """A matcher for files in a tree.""" + def __init__(self, directories): + self.dirs = directories[:] + + def add(self, directory): + """Add another directory to the list we match for.""" + self.dirs.append(directory) + + def match(self, fpath): + """Does `fpath` indicate a file in one of our trees?""" + for d in self.dirs: + if fpath.startswith(d): + if fpath == d: + # This is the same file! + return True + if fpath[len(d)] == os.sep: + # This is a file in the directory + return True + return False + +class FnmatchMatcher(object): + """A matcher for files by filename pattern.""" + def __init__(self, pats): + self.pats = pats[:] + + def match(self, fpath): + """Does `fpath` match one of our filename patterns?""" + for pat in self.pats: + if fnmatch.fnmatch(fpath, pat): + return True + return False -- cgit v1.2.1