From f0377ae91de58d3b7cb4f11a967eb6b4ebf2dc9b Mon Sep 17 00:00:00 2001 From: scossu Date: Wed, 11 Sep 2024 18:58:16 -0400 Subject: [PATCH] Fix init-db call and circular dep. --- entrypoint.sh | 2 +- scriptshifter/tables/__init__.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2917bf4..ccecb7f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,7 +12,7 @@ fi host=${TXL_WEBAPP_HOST:-"0.0.0.0"} port=${TXL_WEBAPP_PORT:-"8000"} -./sscli admin init--db +./sscli admin init-db if [ "${FLASK_ENV}" == "development" ]; then exec flask run -h $host -p $port diff --git a/scriptshifter/tables/__init__.py b/scriptshifter/tables/__init__.py index 01d9e62..24ee217 100644 --- a/scriptshifter/tables/__init__.py +++ b/scriptshifter/tables/__init__.py @@ -151,8 +151,12 @@ def init_db(): """ # Create parent diretories if necessary. # If the DB already exists, it will be overwritten ONLY on success at - # thhis point. - makedirs(path.dirname(TMP_DB_PATH), exist_ok=True) + # hhis point. + if path.isfile(TMP_DB_PATH): + # Remove previous temp file (possibly from failed attempt) + unlink(TMP_DB_PATH) + else: + makedirs(path.dirname(TMP_DB_PATH), exist_ok=True) conn = sqlite3.connect(TMP_DB_PATH) @@ -162,9 +166,11 @@ def init_db(): conn.executescript(fh.read()) # Populate tables. + with open(path.join(TABLE_DIR, "index.yml")) as fh: + tlist = load(fh, Loader=Loader) try: with conn: - for tname, tdata in list_tables().items(): + for tname, tdata in tlist.items(): res = conn.execute( """INSERT INTO tbl_language ( name, label, marc_code, description