From 54064e32075c8fa0f58e8e4360662d79086ebc5d Mon Sep 17 00:00:00 2001 From: Joerg Herbel Date: Tue, 21 May 2024 15:57:41 +0200 Subject: [PATCH] Rename modes: pot --> update-sources, po --> update-translations The new names are more precise and easier to understand. --- checkmk_weblate_syncer/__main__.py | 22 ++++++++++++------- checkmk_weblate_syncer/cli.py | 7 +++--- checkmk_weblate_syncer/config.py | 4 ++-- .../{pot.py => update_sources.py} | 4 ++-- .../{po.py => update_translations.py} | 4 ++-- tests/{test_pot.py => test_update_sources.py} | 2 +- ...test_po.py => test_update_translations.py} | 2 +- 7 files changed, 26 insertions(+), 19 deletions(-) rename checkmk_weblate_syncer/{pot.py => update_sources.py} (96%) rename checkmk_weblate_syncer/{po.py => update_translations.py} (97%) rename tests/{test_pot.py => test_update_sources.py} (96%) rename tests/{test_po.py => test_update_translations.py} (98%) diff --git a/checkmk_weblate_syncer/__main__.py b/checkmk_weblate_syncer/__main__.py index 81e95c5..30445f8 100644 --- a/checkmk_weblate_syncer/__main__.py +++ b/checkmk_weblate_syncer/__main__.py @@ -3,10 +3,10 @@ from typing import TypeVar, assert_never from .cli import Mode, parse_arguments -from .config import PoModeConfig, PotModeConfig +from .config import UpdateSourcesConfig, UpdateTranslationsConfig from .logging import LOGGER, configure_logger -from .po import run as run_po_mode -from .pot import run as run_pot_mode +from .update_sources import run as run_update_sources +from .update_translations import run as run_update_translations def _main() -> None: @@ -14,15 +14,21 @@ def _main() -> None: configure_logger(args.log_level) match args.mode: - case Mode.POT: - sys.exit(run_pot_mode(_load_config(args.config_path, PotModeConfig))) - case Mode.PO: - sys.exit(run_po_mode(_load_config(args.config_path, PoModeConfig))) + case Mode.UPDATE_SOURCES: + sys.exit( + run_update_sources(_load_config(args.config_path, UpdateSourcesConfig)) + ) + case Mode.UPDATE_TRANSLATIONS: + sys.exit( + run_update_translations( + _load_config(args.config_path, UpdateTranslationsConfig) + ) + ) case _: assert_never(args.mode) -_ConfigTypeT = TypeVar("_ConfigTypeT", PotModeConfig, PoModeConfig) +_ConfigTypeT = TypeVar("_ConfigTypeT", UpdateSourcesConfig, UpdateTranslationsConfig) def _load_config(config_path: Path, config_type: type[_ConfigTypeT]) -> _ConfigTypeT: diff --git a/checkmk_weblate_syncer/cli.py b/checkmk_weblate_syncer/cli.py index f492ee6..7cd734e 100644 --- a/checkmk_weblate_syncer/cli.py +++ b/checkmk_weblate_syncer/cli.py @@ -8,8 +8,8 @@ class Mode(Enum): - POT = "pot" - PO = "po" + UPDATE_SOURCES = "update-sources" + UPDATE_TRANSLATIONS = "update-translations" def _parse_log_level(raw: int) -> int: @@ -33,7 +33,8 @@ def parse_arguments() -> Arguments: type=str, choices=[mode.value for mode in Mode], metavar="MODE", - help="Operation mode. pot: Update pot file. po: Update po files.", + help="Operation mode. update-sources: Update source strings (.pot file). " + "update-translations: Update translations (.po files).", ) parser.add_argument( "config_path", diff --git a/checkmk_weblate_syncer/config.py b/checkmk_weblate_syncer/config.py index 6063baa..cfea333 100644 --- a/checkmk_weblate_syncer/config.py +++ b/checkmk_weblate_syncer/config.py @@ -25,7 +25,7 @@ class BaseConfig(BaseModel, frozen=True): locale_repository: RepositoryConfig -class PotModeConfig(BaseConfig, frozen=True): +class UpdateSourcesConfig(BaseConfig, frozen=True): checkmk_pot_generation_script: Annotated[ Path, AfterValidator(_validate_path_is_relative) ] @@ -38,6 +38,6 @@ class PoFilePair(BaseModel, frozen=True): locale: Annotated[Path, AfterValidator(_validate_path_is_relative)] -class PoModeConfig(BaseConfig, frozen=True): +class UpdateTranslationsConfig(BaseConfig, frozen=True): po_file_pairs: Sequence[PoFilePair] commit_message: str diff --git a/checkmk_weblate_syncer/pot.py b/checkmk_weblate_syncer/update_sources.py similarity index 96% rename from checkmk_weblate_syncer/pot.py rename to checkmk_weblate_syncer/update_sources.py index 860a684..7f90eb6 100644 --- a/checkmk_weblate_syncer/pot.py +++ b/checkmk_weblate_syncer/update_sources.py @@ -3,12 +3,12 @@ from subprocess import CalledProcessError from subprocess import run as run_subprocess -from .config import PotModeConfig +from .config import UpdateSourcesConfig from .git import commit_and_push_files, repository_in_clean_state from .logging import LOGGER -def run(config: PotModeConfig) -> int: +def run(config: UpdateSourcesConfig) -> int: repository_in_clean_state(config.checkmk_repository) locale_repo = repository_in_clean_state(config.locale_repository) diff --git a/checkmk_weblate_syncer/po.py b/checkmk_weblate_syncer/update_translations.py similarity index 97% rename from checkmk_weblate_syncer/po.py rename to checkmk_weblate_syncer/update_translations.py index caa2011..7a056e0 100644 --- a/checkmk_weblate_syncer/po.py +++ b/checkmk_weblate_syncer/update_translations.py @@ -7,7 +7,7 @@ from git import Repo -from .config import PoFilePair, PoModeConfig, RepositoryConfig +from .config import PoFilePair, RepositoryConfig, UpdateTranslationsConfig from .git import commit_and_push_files, repository_in_clean_state from .logging import LOGGER @@ -23,7 +23,7 @@ class _Failure: path: Path -def run(config: PoModeConfig) -> int: +def run(config: UpdateTranslationsConfig) -> int: checkmk_repo = repository_in_clean_state(config.checkmk_repository) repository_in_clean_state(config.locale_repository) diff --git a/tests/test_pot.py b/tests/test_update_sources.py similarity index 96% rename from tests/test_pot.py rename to tests/test_update_sources.py index c30264c..9244a84 100644 --- a/tests/test_pot.py +++ b/tests/test_update_sources.py @@ -1,6 +1,6 @@ from pathlib import Path -from checkmk_weblate_syncer.pot import _make_soure_string_locations_relative +from checkmk_weblate_syncer.update_sources import _make_soure_string_locations_relative def test_make_soure_string_locations_relative() -> None: diff --git a/tests/test_po.py b/tests/test_update_translations.py similarity index 98% rename from tests/test_po.py rename to tests/test_update_translations.py index b023942..bf09621 100644 --- a/tests/test_po.py +++ b/tests/test_update_translations.py @@ -1,4 +1,4 @@ -from checkmk_weblate_syncer.po import ( +from checkmk_weblate_syncer.update_translations import ( _remove_last_translator, _remove_source_string_locations, )