2020-04-09 21:13:20 +00:00
|
|
|
"""Translation utils."""
|
2020-04-10 21:17:09 +00:00
|
|
|
import argparse
|
2020-04-09 21:13:20 +00:00
|
|
|
import os
|
|
|
|
import pathlib
|
2020-04-10 00:52:33 +00:00
|
|
|
import subprocess
|
2020-04-09 21:13:20 +00:00
|
|
|
|
|
|
|
from .error import ExitApp
|
|
|
|
|
|
|
|
|
2020-04-17 16:47:49 +00:00
|
|
|
def get_base_arg_parser() -> argparse.ArgumentParser:
|
2020-04-10 21:17:09 +00:00
|
|
|
"""Get a base argument parser."""
|
|
|
|
parser = argparse.ArgumentParser(description="Home Assistant Translations")
|
|
|
|
parser.add_argument(
|
2020-04-15 20:53:52 +00:00
|
|
|
"action",
|
|
|
|
type=str,
|
2020-04-28 17:35:38 +00:00
|
|
|
choices=["clean", "develop", "download", "frontend", "migrate", "upload"],
|
2020-04-10 21:17:09 +00:00
|
|
|
)
|
|
|
|
parser.add_argument("--debug", action="store_true", help="Enable log output")
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
2020-04-09 21:13:20 +00:00
|
|
|
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()
|
2020-04-10 00:52:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_current_branch():
|
|
|
|
"""Get current branch."""
|
|
|
|
return (
|
|
|
|
subprocess.run(
|
|
|
|
["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE
|
|
|
|
)
|
|
|
|
.stdout.decode()
|
|
|
|
.strip()
|
|
|
|
)
|