Error handling

This commit is contained in:
jamesrom
2023-10-07 09:39:53 +11:00
parent 43dc648b05
commit 92e9012fb6
2 changed files with 39 additions and 9 deletions

View File

@ -8,15 +8,24 @@ def filter_ignored(files):
Filter out files that match the ignore patterns.
"""
# load regex patterns, and translate glob patterns to regex
patterns = get_settings().ignore.regex
patterns += [fnmatch.translate(glob) for glob in get_settings().ignore.glob]
try:
# load regex patterns, and translate glob patterns to regex
patterns = get_settings().ignore.regex
patterns += [fnmatch.translate(glob) for glob in get_settings().ignore.glob]
# compile regex patterns
compiled_patterns = [re.compile(r) for r in patterns]
# compile all valid patterns
compiled_patterns = []
for r in patterns:
try:
compiled_patterns.append(re.compile(r))
except re.error:
pass
# keep filenames that _don't_ match the ignore regex
for r in compiled_patterns:
files = [f for f in files if not r.match(f.filename)]
# keep filenames that _don't_ match the ignore regex
for r in compiled_patterns:
files = [f for f in files if not r.match(f.filename)]
except Exception as e:
print(f"Could not filter file list: {e}")
return files