-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.py
More file actions
91 lines (77 loc) · 2.99 KB
/
Copy pathsync.py
File metadata and controls
91 lines (77 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Run the complete SHPD translation synchronization workflows."""
from __future__ import annotations
import argparse
import subprocess
import sys
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent
def _run(script: str, *arguments: str) -> None:
command = [sys.executable, str(BASE_DIR / script), *arguments]
print(f"\n== {script} ==")
completed = subprocess.run(command, cwd=BASE_DIR, check=False)
if completed.returncode:
raise RuntimeError(f"{script} failed with exit code {completed.returncode}")
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers(dest="workflow", required=True)
import_parser = subparsers.add_parser(
"import-transifex",
help="Download Transifex data and import it into ParaTranz.",
)
import_parser.add_argument(
"--source-only",
action="store_true",
help="Update ParaTranz source strings without importing targets.",
)
import_parser.add_argument(
"--sync-metadata",
action="store_true",
help="One-time import of latest Transifex attribution into context.",
)
import_parser.add_argument(
"--force-translations",
action="store_true",
help="Overwrite human-edited ParaTranz translations (normally unsafe).",
)
subparsers.add_parser(
"publish-paratranz",
help="Publish current ParaTranz translations to reviewed Transifex.",
)
return parser.parse_args()
def main() -> int:
args = parse_args()
if args.workflow == "import-transifex" and args.source_only:
if args.force_translations or args.sync_metadata:
print(
"--source-only cannot be combined with --force-translations "
"or --sync-metadata"
)
return 2
try:
if args.workflow == "import-transifex":
_run("source_download_transifex.py")
if args.source_only:
_run("properties_converter.py", "--source-only")
else:
download_args = () if args.sync_metadata else ("--skip-metadata",)
_run("download_transifex.py", *download_args)
_run("properties_converter.py")
upload_args: list[str] = []
if args.source_only:
upload_args.append("--source-only")
if args.sync_metadata:
upload_args.append("--sync-metadata")
if args.force_translations:
upload_args.append("--force-translations")
_run("upload_paratranz.py", *upload_args)
else:
_run("download_paratranz.py")
_run("csv_converter.py", "--translation-only")
_run("upload_transifex.py")
print("\nWorkflow completed successfully.")
return 0
except (OSError, RuntimeError) as exc:
print(f"\nWorkflow stopped: {exc}")
return 1
if __name__ == "__main__":
raise SystemExit(main())