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
|
||||
RUN pip install -r requirements.txt
|
||||
COPY . /app
|
||||
CMD ["scripts/run.sh"]
|
||||
RUN chmod +x scripts/run.sh
|
||||
CMD ["sh", "scripts/run.sh"]
|
@ -1,13 +1,18 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
|
||||
def create_connection(db_file):
|
||||
def create_connection(path: str, filename: str):
|
||||
""" create a database connection to a SQLite database """
|
||||
conn = None
|
||||
try:
|
||||
print("Opening Database file and ensuring table integrity")
|
||||
conn = sqlite3.connect(db_file)
|
||||
# Make the directory for the file to go into
|
||||
create_directory(path)
|
||||
|
||||
print("Opening Database file and ensuring table integrity")
|
||||
conn = sqlite3.connect(path + filename)
|
||||
|
||||
print("Database file open")
|
||||
# Execute creation scripts
|
||||
sql = open("scripts/create_tables.sql", "r");
|
||||
conn.executescript(sql.read())
|
||||
@ -20,6 +25,12 @@ def create_connection(db_file):
|
||||
if conn:
|
||||
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__':
|
||||
create_connection(r"./data/wmgzon.db")
|
||||
create_connection(r"./data/", r"wmgzon.db")
|
||||
|
Loading…
Reference in New Issue
Block a user