Permalink
Cannot retrieve contributors at this time
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?
eoa2-xmldb/scripts/run.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
80 lines (63 sloc)
1.55 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from stop import stop | |
from utils.settings import BASE_DIR, load_config | |
from utils.functions import exec_in_xmldb, run | |
from pathlib import Path | |
import subprocess | |
import shlex | |
import os | |
import shutil | |
from time import sleep | |
XMLDB_WAIT_TIME=20 | |
def init_xml_db( config ): | |
try: | |
subprocess.check_call( | |
shlex.split( "docker-compose up -d xmldb" ), | |
) | |
print( "wait {}s for the xml database to get ready... :-P".format( XMLDB_WAIT_TIME ) ) | |
sleep( XMLDB_WAIT_TIME ) | |
exec_in_xmldb( | |
"--recurse-dirs", | |
"--parse", "{RES_DIR_IN_CONTAINER}/xml".format( | |
RES_DIR_IN_CONTAINER = config['RES_DIR_IN_CONTAINER'] | |
) | |
) | |
except: | |
subprocess.check_call( | |
shlex.split( "docker-compose down" ), | |
) | |
def copy_dir(src, dst): | |
print( "'{}' -> '{}'".format( src, dst ) ) | |
if Path(dst).exists(): | |
shutil.rmtree( | |
dst | |
) | |
shutil.copytree( | |
src=src, | |
dst=dst | |
) | |
if __name__ == '__main__': | |
from argparse import ArgumentParser | |
config = load_config() | |
parser = ArgumentParser( | |
description="run the webserver" | |
) | |
parser.add_argument( | |
"--build", | |
action = "store_true" | |
) | |
parser.add_argument( | |
"CMD", | |
nargs="*" | |
) | |
args = parser.parse_args() | |
stop( | |
env = config | |
) | |
CMD= vars(args)['CMD'] | |
run( | |
env=config, | |
build = args.build, | |
cmd=CMD | |
) | |
init_xml_db( config ) |