manage.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import argparse
  2. import os
  3. import shutil
  4. import subprocess
  5. import sys
  6. from anonflow import __version_str__, paths
  7. def check_translations():
  8. mo_files, po_files = set(), set()
  9. for root, dirs, files in os.walk(paths.TRANSLATIONS_DIR):
  10. for file in files:
  11. if file.endswith(".mo"):
  12. mo_files.add(file[:-3])
  13. if file.endswith(".po"):
  14. po_files.add(file[:-3])
  15. return mo_files == po_files
  16. def compile_translations():
  17. if not shutil.which("pybabel"):
  18. raise RuntimeError("Pybabel not found.")
  19. subprocess.run(["pybabel", "compile", "-d", paths.TRANSLATIONS_DIR], check=True)
  20. print("Translations compilation done.")
  21. def main():
  22. os.environ["VERSION"] = __version_str__
  23. parser = argparse.ArgumentParser(description="Anonflow project manager")
  24. subparsers = parser.add_subparsers(dest="command", required=True)
  25. subparsers.add_parser("start", help="Run the application locally")
  26. deploy_parser = subparsers.add_parser("deploy", help="Build and manage containers via docker compose")
  27. deploy_parser.add_argument("docker_args", nargs=argparse.REMAINDER, help="Additional docker compose commands")
  28. args = parser.parse_args()
  29. try:
  30. if not check_translations():
  31. compile_translations()
  32. if args.command == "start":
  33. print("Running 'python -m anonflow'")
  34. subprocess.run([sys.executable, "-m", "anonflow"], check=True)
  35. elif args.command == "deploy":
  36. if not args.docker_args:
  37. print("Running 'docker compose up --build'")
  38. subprocess.run(["docker", "compose", "up", "--build"])
  39. else:
  40. print(f"Running 'docker compose {' '.join(args.docker_args)}'")
  41. subprocess.run(["docker", "compose"] + args.docker_args)
  42. except KeyboardInterrupt:
  43. pass
  44. if __name__ == "__main__":
  45. main()