def _ignore_pathname(self, restype, dirname, pathname, ignored=False): """ Return `True` if the `gitignore`(5)-style `~/.blueprintignore` file says the given file should be ignored. The starting state of the file may be overridden by setting `ignored` to `True`. """ pathname = util.unicodeme(pathname) # Determine if the `pathname` matches the `pattern`. `filename` is # given as a convenience. See `gitignore`(5) for the rules in play. def match(filename, pathname, pattern): dir_only = '/' == pattern[-1] pattern = pattern.rstrip('/') if '/' not in pattern: if fnmatch.fnmatch(filename, pattern): return os.path.isdir(pathname) if dir_only else True else: for p in glob.glob(os.path.join(dirname, pattern)): p = util.unicodeme(p) if pathname == p or pathname.startswith('{0}/'.format(p)): return os.path.isdir(pathname) if dir_only else True return False # Iterate over exclusion rules until a match is found. Then iterate # over inclusion rules that appear later. If there are no matches, # include the file. If only an exclusion rule matches, exclude the # file. If an inclusion rule also matches, include the file. filename = os.path.basename(pathname) for pattern, negate in self[restype]: if ignored != negate or not match(filename, pathname, pattern): continue ignored = not ignored return ignored
def match(filename, pathname, pattern): dir_only = '/' == pattern[-1] pattern = pattern.rstrip('/') if '/' not in pattern: if fnmatch.fnmatch(filename, pattern): return os.path.isdir(pathname) if dir_only else True else: for p in glob.glob(os.path.join(dirname, pattern)): p = util.unicodeme(p) if pathname == p or pathname.startswith('{0}/'.format(p)): return os.path.isdir(pathname) if dir_only else True return False