22import os
33import sys
44
5+ # Django management command customized for eGSIM. In production,
6+ # you can copy this file next to your .env location, providing you execute this
7+ # script with python venv activated and this repo installed. Also remember to
8+ # chmod 640 .env AND chown root:<egsim_user> .env)
9+
510if __name__ == "__main__" :
6- os .environ .setdefault ("DJANGO_SETTINGS_MODULE" , "egsim.settings" )
7- try :
8- from django .core .management import execute_from_command_line
9- except ImportError :
10- # The above import may fail for some other reason. Ensure that the
11- # issue is really that Django is missing to avoid masking other
12- # exceptions on Python 2.
13- try :
14- import django
15- except ImportError :
16- raise ImportError (
17- "Couldn't import Django. Are you sure it's installed and "
18- "available on your PYTHONPATH environment variable? Did you "
19- "forget to activate a virtual environment?"
20- )
21- raise
22- execute_from_command_line (sys .argv )
11+ # Line commented (force settings file):
12+ # os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangosnippets.settings.development")
13+
14+ # Simple .env read (no dotenv package), we need control to implement the same
15+ # systemd logic (which is stricter, e.g., no spaces)
16+ dotenv_path = os .path .join (os .path .dirname (__file__ ), '.env' )
17+ if os .path .isfile (dotenv_path ):
18+ with open (dotenv_path , encoding = "utf-8" ) as f :
19+ for line in f :
20+ line = line .strip ()
21+ if not line or line .startswith ("#" ):
22+ continue
23+ key , value = line .split ("=" , 1 )
24+ print (f'{ key } ={ value } ' )
25+ os .environ .setdefault (key , value )
26+
27+ from django .core .management import execute_from_command_line
28+ execute_from_command_line (sys .argv )
0 commit comments