From c06ebc29dc7be98a4481b337278fa8fbb767239b Mon Sep 17 00:00:00 2001 From: iou1name Date: Sun, 2 Jun 2019 19:51:32 -0400 Subject: [PATCH] server creates dummy db for initial upload --- overwrought_master.py | 2 +- overwrought_server.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) mode change 100644 => 100755 overwrought_master.py mode change 100644 => 100755 overwrought_server.py diff --git a/overwrought_master.py b/overwrought_master.py old mode 100644 new mode 100755 index 3f21ad2..acc07a8 --- a/overwrought_master.py +++ b/overwrought_master.py @@ -255,7 +255,7 @@ def post_pack(): for mod in mods: files[mod.filename] = open(os.path.join('mods', mod.filename), 'rb') files[config_master.modpack_name + '.html'] = open( - config_master.modpack_name, 'rb') + config_master.modpack_name +'.html', 'rb') res = requests.post( url=config_master.remote_addr + '/post', diff --git a/overwrought_server.py b/overwrought_server.py old mode 100644 new mode 100755 index 1b1dbee..9222a1f --- a/overwrought_server.py +++ b/overwrought_server.py @@ -2,6 +2,7 @@ """ The overwrought server, for exchanging mods from master to slave recipients. """ +import os import json import sqlite3 import threading @@ -13,6 +14,22 @@ import config_server app = Flask(__name__) app.config['db_lock'] = threading.Lock() +os.makedirs('mods', exist_ok=True) + +def init_db(): + """ + If no database is found, a dummy database is created to allow the + initial modpack upload to go smoothly. + """ + con = sqlite3.connect('modpack.db') + cur = con.cursor() + try: + cur.execute("SELECT filename FROM mod").fetchone() + except sqlite3.OperationalError: + cur.execute("CREATE TABLE mod(filename TEXT)") + con.commit() + con.close() +init_db() @app.route('/') def index():