-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsgi.py
50 lines (36 loc) · 1.05 KB
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import os
from src.app import make_app, db
app = make_app()
HOST = "*:5000"
def migrate_db():
print("Migrating DB")
from src.models import Library, NovelCache
with app.app_context():
db.create_all()
def main(args):
if not os.path.exists("./data.db"):
migrate_db()
if args.migrate:
return migrate_db()
if args.debug:
app.run(debug=True)
else:
from waitress import serve
print(f"Serving on {HOST}")
serve(app, listen=HOST)
def str2bool(argument: str):
if argument is None:
return None
if argument.lower() in ("yes", "true", "t", "y", "1"):
return True
elif argument.lower() in ("no", "false", "f", "n", "0"):
return False
else:
return None
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--debug", type=str2bool, nargs="?", const=True, default=False)
parser.add_argument("--migrate", type=str2bool, nargs="?", const=True)
args = parser.parse_args()
main(args)