From 4af41fddfb280142e61483601b8a0be6c0c0094a Mon Sep 17 00:00:00 2001 From: insolor <2442833+insolor@users.noreply.github.com> Date: Fri, 3 May 2024 10:01:22 +0300 Subject: [PATCH] Removed csv_bisect cli --- df_translation_toolkit/csv_bisect/__init__.py | 0 df_translation_toolkit/csv_bisect/cli.py | 6 -- .../csv_bisect/csv_bisect.py | 71 ------------------- pyproject.toml | 1 - 4 files changed, 78 deletions(-) delete mode 100644 df_translation_toolkit/csv_bisect/__init__.py delete mode 100644 df_translation_toolkit/csv_bisect/cli.py delete mode 100644 df_translation_toolkit/csv_bisect/csv_bisect.py diff --git a/df_translation_toolkit/csv_bisect/__init__.py b/df_translation_toolkit/csv_bisect/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/df_translation_toolkit/csv_bisect/cli.py b/df_translation_toolkit/csv_bisect/cli.py deleted file mode 100644 index 7a650c1..0000000 --- a/df_translation_toolkit/csv_bisect/cli.py +++ /dev/null @@ -1,6 +0,0 @@ -import typer - -from df_translation_toolkit.csv_bisect import csv_bisect - -app = typer.Typer() -app.command(name="csv_bisect")(csv_bisect.main) diff --git a/df_translation_toolkit/csv_bisect/csv_bisect.py b/df_translation_toolkit/csv_bisect/csv_bisect.py deleted file mode 100644 index d5a49a6..0000000 --- a/df_translation_toolkit/csv_bisect/csv_bisect.py +++ /dev/null @@ -1,71 +0,0 @@ -import shutil -from pathlib import Path - -from df_translation_toolkit.utils import csv_utils -from df_translation_toolkit.utils.backup import backup - - -def split_left(start, end): - mid = (start + end) // 2 - return start, mid - - -def split_right(start, end): - mid = (start + end) // 2 - return mid, end - - -def bisect(file_path: Path, encoding: str, data: list[list[str]]): - def _bisect(start: int, end: int, bad: bool = False) -> bool: - """ - returns: - - True -> found - - False -> not found - """ - if start >= end: - print("Empty slice, step back") - return False - - print(f"From {start} to {end} (in total {end - start})") - csv_utils.write_csv(file_path, encoding, data[start:end]) - - if bad: - confirmed = True - else: - confirmed = input("Is it bad (y/n)? ").upper() == "y" - - if not confirmed: - return False - - if start == end - 1: - print(f"Found string, line number {start+1}:") - print(data[start]) - - confirmed = input("Exclude from csv (y/n)? ").upper() == "y" - if confirmed: - csv_utils.write_csv(file_path, encoding, data[:start] + data[start + 1 :]) - - return True - - print("Trying left half") - result = _bisect(*split_left(start, end)) - if result: - return result - - print("Trying right half") - return _bisect(*split_right(start, end), bad=True) - - _bisect(0, len(data), bad=True) - - -def main(csv_file: Path, encoding: str): - assert csv_file.is_file(), f"{csv_file.name} is not a file" - - try: - with backup(csv_file, overwrite=True) as backup_path: - data = list(csv_utils.read_csv(backup_path, encoding)) - bisect(csv_file, encoding, data) - finally: - confirmed = input("Restore from backup (y/n)? ").upper() == "y" - if confirmed: - shutil.copy(backup_path, csv_file) diff --git a/pyproject.toml b/pyproject.toml index f4f4d1c..68db30d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,6 @@ convert_hardcoded = "df_translation_toolkit.convert.hardcoded_po_to_csv:app" convert_objects = "df_translation_toolkit.convert.objects_po_to_csv:app" create_pot = "df_translation_toolkit.create_pot.cli:app" create_mod = "df_translation_toolkit.create_mod.cli:app" -csv_bisect = "df_translation_toolkit.csv_bisect.cli:app" [build-system] requires = ["poetry-core>=1.0.0"]