Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #87 from Seluj78/bugfix/math-folder-total
Browse files Browse the repository at this point in the history
  • Loading branch information
Seluj78 authored Oct 15, 2020
2 parents ed1f613 + e20f2d4 commit 7a300c3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .potodoignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
venv/
venv/
2 changes: 1 addition & 1 deletion potodo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Jules Lasne"""
__email__ = "[email protected]"
__version__ = "0.17.1"
__version__ = "0.17.3"
1 change: 1 addition & 0 deletions potodo/po_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, path: Path):
] = self.pofile.untranslated_entries()
self.untranslated_nb: int = len(self.untranslated_entries)

self.entries_count: int = len([e for e in self.pofile if not e.obsolete])
self.percent_translated: int = self.pofile.percent_translated()
self.po_file_size = len(self.pofile) - self.obsolete_nb
self.filename_dir: str = self.directory + "/" + self.filename
Expand Down
26 changes: 15 additions & 11 deletions potodo/potodo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import json
import logging
import statistics
import webbrowser
from pathlib import Path
from typing import Any
Expand All @@ -28,7 +27,7 @@
def print_dir_stats(
directory_name: str,
buffer: Sequence[str],
folder_stats: Sequence[int],
folder_stats: Dict[str, int],
printed_list: Sequence[bool],
) -> None:
"""This function prints the directory name, its stats and the buffer"""
Expand All @@ -38,25 +37,28 @@ def print_dir_stats(
# folder stats and file(s) Each time a file is went over True
# or False is placed in the printed_list list. If False is
# placed it means it doesnt need to be printed
print(f"\n\n# {directory_name} ({statistics.mean(folder_stats):.2f}% done)\n")

folder_completion = 100 * folder_stats["translated"] / folder_stats["total"]

print(f"\n\n# {directory_name} ({folder_completion:.2f}% done)\n")
print("\n".join(buffer))
logging.debug("Not printing directory %s", directory_name)


def add_dir_stats(
directory_name: str,
buffer: List[Dict[str, str]],
folder_stats: Sequence[int],
folder_stats: Dict[str, int],
printed_list: Sequence[bool],
all_stats: List[Dict[str, Any]],
) -> None:
"""Appends directory name, its stats and the buffer to stats"""
if any(printed_list):
pc_translated = statistics.mean(folder_stats)
folder_completion = 100 * folder_stats["translated"] / folder_stats["total"]
all_stats.append(
dict(
name=f"{directory_name}/",
percent_translated=float(f"{pc_translated:.2f}"),
percent_translated=float(f"{folder_completion:.2f}"),
files=buffer,
)
)
Expand Down Expand Up @@ -120,7 +122,7 @@ def exec_potodo(
}

try:
ignore_matches = parse_gitignore(path / ".potodoignore")
ignore_matches = parse_gitignore(".potodoignore", base_dir=path)
except FileNotFoundError:
ignore_matches = parse_gitignore("/dev/null")

Expand Down Expand Up @@ -169,7 +171,7 @@ def exec_potodo(
for directory_name, po_files in sorted(po_files_and_dirs.items()):
# For each directory and files in this directory
buffer: List[Any] = []
folder_stats: List[int] = []
folder_stats: Dict[str, int] = {"translated": 0, "total": 0}
printed_list: List[bool] = []

for po_file in sorted(po_files):
Expand Down Expand Up @@ -217,7 +219,7 @@ def exec_potodo(

def buffer_add(
buffer: List[Any],
folder_stats: List[int],
folder_stats: Dict[str, int],
printed_list: List[bool],
po_file_stats: PoFileStats,
issue_reservations: Dict[str, Tuple[Any, Any]],
Expand All @@ -244,7 +246,8 @@ def buffer_add(
):

# add the percentage of the file to the stats of the folder
folder_stats.append(po_file_stats.percent_translated)
folder_stats["translated"] += po_file_stats.translated_nb
folder_stats["total"] += po_file_stats.entries_count

if not json_format:
# don't print that file
Expand Down Expand Up @@ -318,7 +321,8 @@ def buffer_add(
buffer.append(s)

# Add the percent translated to the folder statistics
folder_stats.append(po_file_stats.percent_translated)
folder_stats["translated"] += po_file_stats.translated_nb
folder_stats["total"] += po_file_stats.entries_count
# Indicate to print the file
printed_list.append(True)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_potodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_output(capsys):
},
{
"name": f"{REPO_DIR}/",
"percent_translated": 16.5,
"percent_translated": 25.0,
"files": [
{
"name": f"{REPO_DIR}/file1",
Expand Down
8 changes: 4 additions & 4 deletions tests/test_potodo_default_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class TestPotodoCLI:
def test_potodo_no_args(self):
output = check_output("potodo").decode("utf-8")
assert "# excluded (50.00% done)" in output
assert "# folder (25.00% done)" in output
assert "# folder (33.33% done)" in output
assert (
"- excluded.po 1 / 2 ( 50.0% translated)" in output
)
assert (
"- file3.po 0 / 1 ( 0.0% translated)" in output
)
assert "# repository (16.50% done)" in output
assert "# repository (25.00% done)" in output
assert (
"- file1.po 1 / 3 ( 33.0% translated), 1 fuzzy"
in output
Expand All @@ -57,7 +57,7 @@ def test_potodo_exclude(self):
"- excluded.po 1 / 2 ( 50.0% translated)"
not in output
)
assert "# repository (16.50% done)" in output
assert "# repository (25.00% done)" in output
assert (
"- file1.po 1 / 3 ( 33.0% translated), 1 fuzzy"
in output
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_potodo_counts(self):
not in output
)
assert "- file4.po 1 to do" in output
assert "# repository (16.50% done)" in output
assert "# repository (25.00% done)" in output
assert (
"- file1.po 2 to do, including 1 fuzzies." in output
)
Expand Down

0 comments on commit 7a300c3

Please sign in to comment.