Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 105 lines (89 sloc) 2.43 KB
#!/usr/bin/env python3
from utils.settings import BASE_DIR, load_config, create_docker_env_file
from utils.functions import exec_in_container, run
from stop import stop
from pathlib import Path
import shlex
import shutil
import pwd
import os
import subprocess
from time import sleep
BASE_DIR = Path( __file__ ).parent.parent
def create_dir(dir):
print( "creating dir '{}'".format( dir ) )
Path(dir).mkdir(
parents = True,
exist_ok = True
)
def copy_dir(src, dst):
print( "'{}' -> '{}'".format( src, dst ) )
if Path(dst).exists():
shutil.rmtree(
dst
)
shutil.copytree(
src=src,
dst=dst
)
def create_dirs( config ):
create_dir(
BASE_DIR / config['DEPENDENCIES_DIR']
)
create_dir(
BASE_DIR / config['HOME_DIR']
)
create_dir(
BASE_DIR / config['INPUT_DIR']
)
create_dir(
BASE_DIR / config['OUTPUT_DIR']
)
in_link = Path(BASE_DIR / config['HOME_DIR'] / 'input' )
if not(in_link.is_symlink()) and not(in_link.exists()):
in_link . symlink_to(
config['INPUT_DIR_IN_CONTAINER'],
target_is_directory = True,
)
out_link = Path(BASE_DIR / config['HOME_DIR'] / 'output' )
if not(out_link.is_symlink()) and not(out_link.exists()):
out_link . symlink_to(
config['OUTPUT_DIR_IN_CONTAINER'],
target_is_directory = True,
)
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser(
description="initialize the repository: create directories, etc"
)
parser.add_argument(
"--build",
action = "store_true",
help = "rebuild docker image from Dockerfile",
)
parser.add_argument(
"-e", "--env",
action = "store_true",
help = "overwrite existing .env file",
)
args = parser.parse_args()
# orig_config_file -> env_file:
create_docker_env_file()
# load env_file:
config = load_config()
create_dirs( config )
# rebuild docker image:
if args.build:
run(
env = config,
build = True,
)
stop(
env = config,
)
# copy example publication to $INPUT_DIR:
copy_dir(
BASE_DIR / config['DEPENDENCIES_DIR'] / 'eoa-publication-model/examples',
BASE_DIR / config['INPUT_DIR'] / 'example'
)
print( "done." )