Commit c32d251b3fdbf65a597bacdf85e51383aa9db922

Authored by Alexis Koralewski
1 parent 12aa6dce
Exists in dev

add environment variables when not using Docker, add an ending message for the installation

Showing 1 changed file with 29 additions and 2 deletions   Show diff stats
pyros.py
... ... @@ -133,6 +133,33 @@ if type(WITH_DOCKER) is str and re.match("^y$|^Y$|^yes$|^Yes$",WITH_DOCKER.rstri
133 133 else :
134 134 WITH_DOCKER = False
135 135  
  136 +ENV_PATH = "docker/.env"
  137 +ENV_SAMPLE_PATH = "docker/.env-sample"
  138 +is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None
  139 +if(is_environment_variables_not_defined):
  140 + try:
  141 + with open(ENV_PATH,"r") as env_file:
  142 + print("Reading env file")
  143 + for line in env_file:
  144 + if(line.startswith("#") and not env_sample_line.strip()):
  145 + continue
  146 + else:
  147 + key,value = line.split("=")
  148 + # setting variables as environment variables
  149 + os.environ[key] = value
  150 + except:
  151 + print(f".env not found at {ENV_PATH}, creating a file at this path from the .env-sample file stored at {ENV_SAMPLE_PATH}\n \
  152 + values from .env-sample will be used as environment variables")
  153 + with open(ENV_SAMPLE_PATH,'r') as env_sample_file:
  154 + with open(ENV_PATH,"w") as env_file:
  155 + for env_sample_line in env_sample_file:
  156 + if(env_sample_line.startswith("#") or not env_sample_line.strip()):
  157 + continue
  158 + key,value = env_sample_line.split("=")
  159 + os.environ[key] = value
  160 + env_file.write(env_sample_line)
  161 + is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None
  162 +
136 163 END_OF_LINE = '\n\n'
137 164 ##VENV_BIN = '/bin/'
138 165 # --------------------------------------------
... ... @@ -437,7 +464,7 @@ def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only
437 464 _updatedb() or die()
438 465 else:
439 466 install_database(VENV)
440   -
  467 + print("You can connect to PyROS as 'pyros' user with the password 'DjangoPyros' ")
441 468 return True
442 469  
443 470  
... ... @@ -1046,7 +1073,7 @@ def install_database(venv):
1046 1073  
1047 1074 # if the mysql_root_password isn't defined, it will ask to enter the password
1048 1075 try:
1049   - # If we're using Docker, a root password should be defined as an environment variable
  1076 + # a root password should be defined as an environment variable
1050 1077 mysql_root_password = os.environ['MYSQL_ROOT_PASSWORD']
1051 1078 except:
1052 1079 # need a space as string so the command ask to the user to write his password.
... ...