arrowcounter/manage.py

40 lines
1.5 KiB
Python
Raw Normal View History

#!/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')
2019-04-28 14:04:26 +00:00
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)
2019-04-28 14:04:26 +00:00
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)