Ver código fonte

Add cli command for emus

Colin Powell 2 anos atrás
pai
commit
ce7d09b524
2 arquivos alterados com 37 adições e 3 exclusões
  1. 36 0
      emus/cli.py
  2. 1 3
      pyproject.toml

+ 36 - 0
emus/cli.py

@@ -0,0 +1,36 @@
+import logging
+import sys
+from os import environ as env
+
+
+if not 'DJANGO_SETTINGS_MODULE' in env:
+    from emus import settings
+
+    env.setdefault('DJANGO_SETTINGS_MODULE', settings.__name__)
+
+
+import django
+
+django.setup()
+
+# this line must be after django.setup() for logging configure
+logger = logging.getLogger('emus')
+
+
+def main():
+    # to get configured settings
+    from django.conf import settings
+
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError as exc:
+        raise ImportError(
+            "Couldn't import Django. Are you sure it's installed and "
+            "available on your PYTHONPATH environment variable? Did you "
+            "forget to activate a virtual environment?"
+        ) from exc
+    execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+    main()

+ 1 - 3
pyproject.toml

@@ -62,9 +62,7 @@ combine_as_imports = true
 exclude_dirs = ["activities/tests/*", "activities/migrations/*"]
 
 [tool.poetry.scripts]
-server = 'scripts:server'
-migrate = 'scripts:migrate'
-shell = 'scripts:shell'
+emus = "emus.cli:main"
 
 [build-system]
 requires = ["poetry-core>=1.0.0"]