Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename modes: pot --> update-sources, po --> update-translations #12

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions checkmk_weblate_syncer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@
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:
args = parse_arguments()
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:
Expand Down
7 changes: 4 additions & 3 deletions checkmk_weblate_syncer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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).",
jherbel marked this conversation as resolved.
Show resolved Hide resolved
)
parser.add_argument(
"config_path",
Expand Down
4 changes: 2 additions & 2 deletions checkmk_weblate_syncer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_pot.py → tests/test_update_sources.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_po.py → tests/test_update_translations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from checkmk_weblate_syncer.po import (
from checkmk_weblate_syncer.update_translations import (
_remove_last_translator,
_remove_source_string_locations,
)
Expand Down