Skip to content

Commit

Permalink
improved scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Nov 27, 2019
1 parent b43997b commit 5a2847c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
2 changes: 2 additions & 0 deletions scripts/config/env.conf → scripts/config/env_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 46 additions & 18 deletions scripts/exit.py
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 7 additions & 3 deletions scripts/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -37,6 +34,7 @@ def copy_dir(src, dst):
)

def create_dirs( config ):

create_dir(
BASE_DIR / config['DATABASE_DATA_DIR']
)
Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down

0 comments on commit 5a2847c

Please sign in to comment.