hass-core/script/translations/util.py
Paulus Schoutsen 7859be6481
Add deduplicate translations script (#96384)
* Add deduplicate script

* Fix forecast_solar incorrect key with space

* Fix utf-8

* Do not create references to other arbitrary other integrations

* Add commented code to only allow applying to referencing integrations

* Tweak

* Bug fix

* Add command line arg for limit reference

* never suggest to update common keys

* Output of script

* Apply suggestions from code review

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>

---------

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
2023-07-13 11:52:50 -04:00

55 lines
1.2 KiB
Python

"""Translation utils."""
import argparse
import os
import pathlib
import subprocess
from .error import ExitApp
def get_base_arg_parser() -> argparse.ArgumentParser:
"""Get a base argument parser."""
parser = argparse.ArgumentParser(description="Home Assistant Translations")
parser.add_argument(
"action",
type=str,
choices=[
"clean",
"deduplicate",
"develop",
"download",
"frontend",
"migrate",
"upload",
],
)
parser.add_argument("--debug", action="store_true", help="Enable log output")
return parser
def get_lokalise_token():
"""Get lokalise token."""
token = os.environ.get("LOKALISE_TOKEN")
if token is not None:
return token
token_file = pathlib.Path(".lokalise_token")
if not token_file.is_file():
raise ExitApp(
"Lokalise token not found in env LOKALISE_TOKEN or file .lokalise_token"
)
return token_file.read_text().strip()
def get_current_branch():
"""Get current branch."""
return (
subprocess.run(
["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE
)
.stdout.decode()
.strip()
)