diff --git a/scripts/config/env.conf b/scripts/config/env_default.conf similarity index 95% rename from scripts/config/env.conf rename to scripts/config/env_default.conf index fbbcc12..4d45193 100644 --- a/scripts/config/env.conf +++ b/scripts/config/env_default.conf @@ -9,6 +9,8 @@ WEB_SERVER_IMAGE=eoa_1_5_webserver ################################################### # volumes: +DEPENDENCIES_DIR=dependencies + RUNTIME_DIR=runtime_data DATABASE_DATA_DIR=${RUNTIME_DIR}/postgres_data diff --git a/scripts/exit.py b/scripts/exit.py index 584c01d..a519370 100755 --- a/scripts/exit.py +++ b/scripts/exit.py @@ -1,44 +1,72 @@ #!/usr/bin/env python3 -from utils.settings import BASE_DIR, load_config +from utils.settings import BASE_DIR, load_config, env_file, create_docker_env_file +from stop import stop from pathlib import Path import shutil import os -def rm_dirs( config ): - path = Path( BASE_DIR, config['RUNTIME_DIR'] ) +def rm_dir( + path +): print( "removing dir '{}'".format( path ) ) shutil.rmtree( path, ignore_errors=True ) - # os.system('rm -rf "{}"'.format( path )) -def rm_docker_env_file( config ): - path = Path( - BASE_DIR / ".env" - ) - print( "removing '{}'".format( path ) ) - shutil.rmtree( - path, - ignore_errors=True - ) +def rm_file( + path +): + if path.is_file(): + print( "removing file '{}'".format( path ) ) + path.unlink() if __name__ == '__main__': from argparse import ArgumentParser + if not env_file.exists(): + create_docker_env_file() config = load_config() parser = ArgumentParser( - description="clean up the repository: remove xml database, remove sql database" + description="clean up the repository. Wont delete anything unless corresponding options are specified. ('--all' removes all)" + ) + parser.add_argument( + "-d", "--deps", + action = "store_true", + help = "remove dependencies", + ) + parser.add_argument( + "-r", "--runtime", + action = "store_true", + help = "remove '{rt_dir}'".format( rt_dir = BASE_DIR / config['RUNTIME_DIR'] ), + ) + parser.add_argument( + "-e", "--env", + action = "store_true", + help = "remove existing .env file", + ) + parser.add_argument( + "--all", + action = "store_true", + help = "purge in every way", ) args = parser.parse_args() - from stop import stop - stop( config ) - rm_dirs( config ) - rm_docker_env_file( config ) + if args.deps or args.all: + rm_dir( + path = BASE_DIR / config['DEPENDENCIES_DIR'] + ) + if args.runtime or args.all: + rm_dir( + path = BASE_DIR / config['RUNTIME_DIR'] + ) + if args.env or args.all: + rm_file( + env_file + ) diff --git a/scripts/init.py b/scripts/init.py index 6f232be..ee9c5cf 100755 --- a/scripts/init.py +++ b/scripts/init.py @@ -12,9 +12,6 @@ import subprocess from time import sleep -BASE_DIR = Path( __file__ ).parent.parent -DEP_DIR = BASE_DIR / "dependencies" - SQLDB_WAIT_TIME=20 @@ -37,6 +34,7 @@ def copy_dir(src, dst): ) def create_dirs( config ): + create_dir( BASE_DIR / config['DATABASE_DATA_DIR'] ) @@ -58,6 +56,12 @@ def install_git_dep( force = False, init_script = None ): + DEP_DIR = BASE_DIR / config['DEPENDENCIES_DIR'] + + create_dir( + BASE_DIR / config['DEPENDENCIES_DIR'] + ) + # remove repo, if necessary: if force and (DEP_DIR / repo_name).exists(): shutil.rmtree( DEP_DIR / repo_name ) diff --git a/scripts/utils/settings.py b/scripts/utils/settings.py index d81ca9e..c3e0f63 100644 --- a/scripts/utils/settings.py +++ b/scripts/utils/settings.py @@ -8,7 +8,7 @@ BASE_DIR = Path( __file__ ).parent.parent.parent SCRIPT_DIR = Path( __file__ ).parent.parent -orig_config_file = SCRIPT_DIR / "config" / "env.conf" +orig_config_file = SCRIPT_DIR / "config" / "env_default.conf" env_file = BASE_DIR / ".env"