2018-08-08 18:07:59 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import sys
|
2018-08-12 18:50:09 +00:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
from os import path
|
2018-08-08 18:07:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-08-12 18:50:09 +00:00
|
|
|
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 \
|
2019-07-27 12:04:44 +00:00
|
|
|
and (sys.argv[1] == 'collectstatic' or sys.argv[1] == 'compilemessages'):
|
2019-04-28 14:04:26 +00:00
|
|
|
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)
|
2018-08-12 18:50:09 +00:00
|
|
|
|
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)
|
2018-08-12 18:50:09 +00:00
|
|
|
|
2018-08-08 18:07:59 +00:00
|
|
|
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)
|