Skip to content

Commit

Permalink
Add the possibility to exclude directories, too, not only files ...
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Jul 21, 2021
1 parent cb1306c commit 3bd7609
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions .pontos-header-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/templates/*
22 changes: 13 additions & 9 deletions pontos/updateheader/updateheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ def _update_file(
def _get_exclude_list(
exclude_file: Path, directories: List[Path]
) -> List[Path]:
"""Tries to get the list of excluded files.
"""Tries to get the list of excluded files / directories.
If a file is given, it will be used. Otherwise it will be searched
in the executed root path.
The ignore file should only contain relative paths like *.py,
not absolute as **/*.py
"""

if exclude_file is None:
exclude_file = ".pontos-header-ignore"
exclude_file = Path(".pontos-header-ignore")
try:
exclude_lines = exclude_file.read_text().split('\n')
except FileNotFoundError:
Expand All @@ -226,9 +226,16 @@ def _get_exclude_list(
if line
]

return [
path.absolute() for glob_paths in expanded_globs for path in glob_paths
]
exclude_list = []
for glob_paths in expanded_globs:
for path in glob_paths:
if path.is_dir():
for efile in path.rglob('*'):
exclude_list.append(efile.absolute())
else:
exclude_list.append(path.absolute())

return exclude_list


def _parse_args(args=None):
Expand Down Expand Up @@ -318,10 +325,7 @@ def main() -> None:
else:
directories = [Path(args.directories)]
# get file paths to exclude
if args.exclude_file:
exclude_list = _get_exclude_list(args.exclude_file, directories)
else:
exclude_list = []
exclude_list = _get_exclude_list(args.exclude_file, directories)
# get files to update
files = [
Path(file)
Expand Down

0 comments on commit 3bd7609

Please sign in to comment.