Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
l8556 committed Apr 10, 2024
1 parent 88c784f commit 66491cf
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions host_tools/utils/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,37 @@ def get_paths(
name_include: str = None,
name_starts_with: str = None
) -> list:
ext_dirs = [join(path, ext_path) for ext_path in exceptions_dirs] if exceptions_dirs else []
if exceptions_dirs:
exceptions_dirs = {join(path, ext_path) for ext_path in (exceptions_dirs or set())}

if extension:
extension = tuple(ext.lower() for ext in extension) if isinstance(extension, tuple) else extension.lower()

file_paths = []

for root, dirs, files in walk(path):
if exceptions_dirs and any(ext_path in root for ext_path in exceptions_dirs):
continue

if dir_include and dir_include not in basename(root):
continue

for filename in files:
if (
exceptions_files and filename in exceptions_files
or exceptions_dirs and [path for path in ext_dirs if path in root]
or dir_include and (dir_include not in basename(root))
or name_include and (name_include not in filename)
or name_starts_with and not filename.startswith(name_starts_with)
):
if exceptions_files and filename in exceptions_files:
continue

if name_include and name_include not in filename:
continue
if names:
file_paths.append(join(root, filename)) if filename in names else ...
elif extension:
if filename.lower().endswith(extension if isinstance(extension, tuple) else extension.lower()):
file_paths.append(join(root, filename))
else:
file_paths.append(join(root, filename))

if name_starts_with and not filename.startswith(name_starts_with):
continue

if names and filename not in names:
continue

if extension and not filename.lower().endswith(extension):
continue

file_paths.append(join(root, filename))

return file_paths

0 comments on commit 66491cf

Please sign in to comment.