|
|
@@ -1,3 +1,4 @@
|
|
|
+import argparse
|
|
|
import os
|
|
|
import shutil
|
|
|
import subprocess
|
|
|
@@ -5,32 +6,7 @@ import sys
|
|
|
|
|
|
from anonflow import __version_str__, paths
|
|
|
|
|
|
-def _check_command(cmd: str):
|
|
|
- return shutil.which(cmd) is not None
|
|
|
-
|
|
|
-def _install_with_pip(package: str):
|
|
|
- if _check_command("pipx"):
|
|
|
- print(f"Trying to install {package} via pipx...")
|
|
|
- subprocess.run(["pipx", "install", package], check=True)
|
|
|
- elif _check_command("pip"):
|
|
|
- print(f"pipx not found. Installing {package} via pip...")
|
|
|
- subprocess.run([sys.executable, "-m", "pip", "install", package], check=True)
|
|
|
- else:
|
|
|
- raise RuntimeError(f"Failed to install {package}. Please check your pip/pipx setup.")
|
|
|
-
|
|
|
-def _compile_translations():
|
|
|
- if not _check_command("pybabel"):
|
|
|
- print("pybabel not found!")
|
|
|
- user_input = input("Do you want to install it? [y/N]: ").strip().lower()
|
|
|
- if user_input == "y":
|
|
|
- _install_with_pip("babel")
|
|
|
- else:
|
|
|
- raise FileNotFoundError("pybabel not found. Please install it first or compile translations manually.")
|
|
|
-
|
|
|
- subprocess.run(["pybabel", "compile", "-d", paths.TRANSLATIONS_DIR], check=True)
|
|
|
- print("Translations compiled successfully!")
|
|
|
-
|
|
|
-def _check_translations():
|
|
|
+def check_translations():
|
|
|
mo_files, po_files = set(), set()
|
|
|
for root, dirs, files in os.walk(paths.TRANSLATIONS_DIR):
|
|
|
for file in files:
|
|
|
@@ -41,19 +17,40 @@ def _check_translations():
|
|
|
|
|
|
return mo_files == po_files
|
|
|
|
|
|
+def compile_translations():
|
|
|
+ if not shutil.which("pybabel"):
|
|
|
+ raise RuntimeError("Pybabel not found.")
|
|
|
+
|
|
|
+ subprocess.run(["pybabel", "compile", "-d", paths.TRANSLATIONS_DIR], check=True)
|
|
|
+ print("Translations compilation done.")
|
|
|
+
|
|
|
def main():
|
|
|
os.environ["VERSION"] = __version_str__
|
|
|
- args = sys.argv[1:]
|
|
|
+
|
|
|
+ parser = argparse.ArgumentParser(description="Anonflow project manager")
|
|
|
+ subparsers = parser.add_subparsers(dest="command", required=True)
|
|
|
+
|
|
|
+ subparsers.add_parser("start", help="Run the application locally")
|
|
|
+
|
|
|
+ deploy_parser = subparsers.add_parser("deploy", help="Build and manage containers via docker compose")
|
|
|
+ deploy_parser.add_argument("docker_args", nargs=argparse.REMAINDER, help="Additional docker compose commands")
|
|
|
+
|
|
|
+ args = parser.parse_args()
|
|
|
|
|
|
try:
|
|
|
- if args:
|
|
|
- if not _check_translations():
|
|
|
- _compile_translations()
|
|
|
-
|
|
|
- if args[0] == "run":
|
|
|
- subprocess.run(["python", "-m", "anonflow"], check=True)
|
|
|
- elif args[0] == "docker" and len(args) > 1:
|
|
|
- subprocess.run(["docker", "compose"] + args[1:], check=True)
|
|
|
+ if not check_translations():
|
|
|
+ compile_translations()
|
|
|
+
|
|
|
+ if args.command == "start":
|
|
|
+ print("Running 'python -m anonflow'")
|
|
|
+ subprocess.run([sys.executable, "-m", "anonflow"], check=True)
|
|
|
+ elif args.command == "deploy":
|
|
|
+ if not args.docker_args:
|
|
|
+ print("Running 'docker compose up --build'")
|
|
|
+ subprocess.run(["docker", "compose", "up", "--build"])
|
|
|
+ else:
|
|
|
+ print(f"Running 'docker compose {' '.join(args.docker_args)}'")
|
|
|
+ subprocess.run(["docker", "compose"] + args.docker_args)
|
|
|
except KeyboardInterrupt:
|
|
|
pass
|
|
|
|