forked from AFPy/potodo
Add "exclude" option.
This commit is contained in:
parent
eafdab2f14
commit
3283a67762
|
@ -53,15 +53,28 @@ class PoFileStats:
|
|||
return self.filename < other.filename
|
||||
|
||||
|
||||
def get_po_files_from_repo(repo_path: str) -> Mapping[str, Sequence[PoFileStats]]:
|
||||
"""Gets all the po files from a given repository. Will return a list
|
||||
with all directories and PoFile instances of `.po` files in those
|
||||
directories.
|
||||
def is_within(file: Path, folder: Path) -> bool:
|
||||
""" Check if `file` is within `folder`'s tree.
|
||||
"""
|
||||
folder = folder.resolve()
|
||||
file = file.resolve()
|
||||
return folder in file.parents
|
||||
|
||||
|
||||
def get_po_files_from_repo(
|
||||
repo_path: str, exclude: List[str]
|
||||
) -> Mapping[str, Sequence[PoFileStats]]:
|
||||
"""Gets all the po files recursively from 'repo_path', excluding those in
|
||||
'exclude'. Return a list with all directories and PoFile instances of
|
||||
`.po` files in those directories.
|
||||
"""
|
||||
|
||||
# Get all the files matching `**/*.po` and not being `.git/` in the given path
|
||||
# Get all the files matching `**/*.po`
|
||||
# not being in any (sub)folder from the exclusion list
|
||||
all_po_files: Sequence[Path] = [
|
||||
file for file in Path(repo_path).glob("**/*.po") if ".git/" not in str(file)
|
||||
file
|
||||
for file in Path(repo_path).rglob("*.po")
|
||||
if not any(is_within(file, Path(excluded)) for excluded in exclude)
|
||||
]
|
||||
|
||||
# Separates each directory and places all pofiles for each directory accordingly
|
||||
|
|
|
@ -80,6 +80,7 @@ def add_dir_stats(
|
|||
|
||||
def exec_potodo(
|
||||
path: str,
|
||||
exclude: List[str],
|
||||
above: int,
|
||||
below: int,
|
||||
fuzzy: bool,
|
||||
|
@ -92,6 +93,7 @@ def exec_potodo(
|
|||
Will run everything based on the given parameters
|
||||
|
||||
:param path: The path to search into
|
||||
:param exclude: folders within 'path' to be ignored
|
||||
:param above: The above threshold
|
||||
:param below: The below threshold
|
||||
:param fuzzy: Should only fuzzies be printed
|
||||
|
@ -107,7 +109,7 @@ def exec_potodo(
|
|||
)
|
||||
|
||||
# Get a dict with the directory name and all po files.
|
||||
po_files_and_dirs = get_po_files_from_repo(path)
|
||||
po_files_and_dirs = get_po_files_from_repo(path, exclude)
|
||||
|
||||
dir_stats: List[Any] = []
|
||||
for directory_name, po_files in sorted(po_files_and_dirs.items()):
|
||||
|
@ -241,6 +243,10 @@ def main() -> None:
|
|||
|
||||
parser.add_argument("-p", "--path", help="execute Potodo in PATH")
|
||||
|
||||
parser.add_argument(
|
||||
"-e", "--exclude", nargs="+", default=[], help="exclude folders"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-a",
|
||||
"--above",
|
||||
|
|
3
tests/fixtures/repository/excluded/file4.po
vendored
Normal file
3
tests/fixtures/repository/excluded/file4.po
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
#: /I/am/excluded.rst:333
|
||||
msgid "Whatever"
|
||||
msgstr "Peu importe"
|
|
@ -7,9 +7,10 @@ FIXTURE_DIR = Path(__file__).resolve().parent / "fixtures"
|
|||
REPO_DIR = "repository"
|
||||
|
||||
|
||||
def test_potodo(capsys):
|
||||
def test_txt_output(capsys):
|
||||
exec_potodo(
|
||||
path=FIXTURE_DIR / REPO_DIR,
|
||||
exclude=list(),
|
||||
above=0,
|
||||
below=100,
|
||||
fuzzy=False,
|
||||
|
@ -27,9 +28,10 @@ def test_potodo(capsys):
|
|||
assert "2 fuzzy" not in captured.out
|
||||
|
||||
|
||||
def test_json_output(capsys):
|
||||
def test_output(capsys):
|
||||
exec_potodo(
|
||||
path=FIXTURE_DIR / REPO_DIR,
|
||||
exclude=["excluded"],
|
||||
above=0,
|
||||
below=100,
|
||||
fuzzy=False,
|
||||
|
|
Loading…
Reference in New Issue
Block a user