Skip to content

Commit

Permalink
init script won' overwrite existing .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Nov 29, 2019
1 parent 314c811 commit e641703
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Dependencies to other git repositories are handled using [git_deps_py](https://g
- Environment variables: see file `.env`

These variables are available inside the `docker-compose.yaml` file and are also loaded into the python scripts.
The file is created/overwritten with default settings by the `init.py` script.
(The `.env` file is initially created with default settings by the `init.py` script)

- Django settings: see `src/eoa/settings.py`

Expand Down
43 changes: 24 additions & 19 deletions scripts/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,31 @@ def load_config(
config = { "PATH": path, ** config }
return config

def create_docker_env_file():
import subprocess
user = subprocess.check_output(
shlex.split("id -u"),
universal_newlines=True
).rstrip("\n")
group = subprocess.check_output(
shlex.split("id -g"),
universal_newlines=True
).rstrip("\n")
def create_docker_env_file(
overwrite = False
):
if overwrite or not(env_file.exists()):
import subprocess
user = subprocess.check_output(
shlex.split("id -u"),
universal_newlines=True
).rstrip("\n")
group = subprocess.check_output(
shlex.split("id -g"),
universal_newlines=True
).rstrip("\n")

print( "user id: {}, group id: {}".format( user, group) )
print( "writing docker .env file to {}, appended user and group".format( env_file ) )
config = __load_orig_config( orig_config_file )
config['config']['USER'] = user
config['config']['GROUP'] = group
__write_as_env(
config,
env_file
)
print( "user id: {}, group id: {}".format( user, group) )
print( "writing docker .env file to {}, appended user and group".format( env_file ) )
config = __load_orig_config( orig_config_file )
config['config']['USER'] = user
config['config']['GROUP'] = group
__write_as_env(
config,
env_file
)
else:
print( f"INFO: '{env_file}' already exists" )

def __load_orig_config( filename ):
config = ConfigParser(
Expand Down

0 comments on commit e641703

Please sign in to comment.