Updated docker and script files to make them more robust
This commit is contained in:
parent
79231a1f0d
commit
f1065b8150
@ -3,4 +3,5 @@ COPY ./requirements.txt /app/requirements.txt
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
COPY . /app
|
COPY . /app
|
||||||
CMD ["scripts/run.sh"]
|
RUN chmod +x scripts/run.sh
|
||||||
|
CMD ["sh", "scripts/run.sh"]
|
@ -1,13 +1,18 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def create_connection(db_file):
|
def create_connection(path: str, filename: str):
|
||||||
""" create a database connection to a SQLite database """
|
""" create a database connection to a SQLite database """
|
||||||
conn = None
|
conn = None
|
||||||
try:
|
try:
|
||||||
print("Opening Database file and ensuring table integrity")
|
# Make the directory for the file to go into
|
||||||
conn = sqlite3.connect(db_file)
|
create_directory(path)
|
||||||
|
|
||||||
|
print("Opening Database file and ensuring table integrity")
|
||||||
|
conn = sqlite3.connect(path + filename)
|
||||||
|
|
||||||
|
print("Database file open")
|
||||||
# Execute creation scripts
|
# Execute creation scripts
|
||||||
sql = open("scripts/create_tables.sql", "r");
|
sql = open("scripts/create_tables.sql", "r");
|
||||||
conn.executescript(sql.read())
|
conn.executescript(sql.read())
|
||||||
@ -20,6 +25,12 @@ def create_connection(db_file):
|
|||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
# Ensure a directory is created given a path to it
|
||||||
|
def create_directory(dir: str):
|
||||||
|
try:
|
||||||
|
os.makedirs(dir)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
create_connection(r"./data/wmgzon.db")
|
create_connection(r"./data/", r"wmgzon.db")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
python ./scripts/create_database.py
|
python ./scripts/create_database.py
|
||||||
python ./app.py
|
python ./app.py
|
Loading…
Reference in New Issue
Block a user