39 lines
1.5 KiB
Python
Executable file
39 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
from dotenv import load_dotenv
|
|
from os import path
|
|
|
|
if __name__ == '__main__':
|
|
env_path = path.join(path.dirname(path.realpath(__file__)), '.env')
|
|
if not os.path.exists(env_path) and len(sys.argv) >= 2 and len(sys.argv) <= 3 \
|
|
and sys.argv[1] == 'collectstatic':
|
|
os.environ['POSTGRES_DB'] = ''
|
|
os.environ['POSTGRES_HOST'] = ''
|
|
os.environ['POSTGRES_USER'] = ''
|
|
os.environ['POSTGRES_PASSWORD'] = ''
|
|
os.environ['DEBUG'] = 'false'
|
|
os.environ['ALLOWED_HOSTS'] = ''
|
|
os.environ['SECURITY_KEY'] = 'dummy-value'
|
|
else:
|
|
load_dotenv(verbose=True,dotenv_path=env_path)
|
|
|
|
check_env_vars = ['POSTGRES_DB', 'POSTGRES_HOST', 'POSTGRES_PASSWORD',
|
|
'POSTGRES_USER', 'DEBUG', 'ALLOWED_HOSTS', 'SECURITY_KEY']
|
|
|
|
for key in check_env_vars:
|
|
if key not in os.environ:
|
|
sys.stderr.write('The mandatory environment ' \
|
|
'variable ' + key + ' is not set\n')
|
|
sys.exit(1)
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'arrowcounter.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)
|