allow to specify several exclude-dir options (#55)

This commit is contained in:
Christophe Nanteuil 2022-12-01 14:44:23 +01:00 committed by GitHub
parent e08a750ef7
commit f790dbb2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -13,10 +13,10 @@ and `pogrep` is a part of it! Go check out [Poutils](https://pypi.org/project/po
Print usage: `pogrep --help`
Find how 'flavors' has already been translated: search recursively in the
current directory, show the names of the matching files, excluding the venv
directory which contains a virtual env:
current directory, show the names of the matching files, excluding the venv and the
locales directories which are not relevant:
`pogrep --recursive --line-number --exclude-dir venv flavor `
`pogrep --recursive --line-number --exclude-dir venv --exclude-dir locales flavor `
Search the word 'typo' in traductions, but not in sources:

View File

@ -273,6 +273,7 @@ def parse_args() -> argparse.Namespace:
)
parser.add_argument(
"--exclude-dir",
action="append",
help="Skip any command-line directory with a name suffix that matches "
"the pattern. "
"When searching recursively, skip any subdirectory whose base name "
@ -319,7 +320,11 @@ def main():
args.pattern = r"(?i)" + args.pattern
files = process_path(args.path, args.recursive)
if args.exclude_dir:
files = [f for f in files if args.exclude_dir.rstrip(os.sep) + os.sep not in f]
files = [
f
for f in files
if not any(excl.rstrip(os.sep) + os.sep in f for excl in args.exclude_dir)
]
errors, results = find_in_po(args.pattern, files, args.no_source, args.translation)
if not args.no_messages:
for error in errors: