server creates dummy db for initial upload

This commit is contained in:
iou1name 2019-06-02 19:51:32 -04:00
parent 6fe9ba59a7
commit c06ebc29dc
2 changed files with 18 additions and 1 deletions

2
overwrought_master.py Normal file → Executable file
View File

@ -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',

17
overwrought_server.py Normal file → Executable file
View File

@ -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():