-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
39 lines (29 loc) · 1.07 KB
/
run.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
import sys
import os
from src.shared.config.conf import Config
from src.tui.script import start
import src.shared.database.sqlite_db as db
from src.web_api.factory import create_flask_app
import json
def create_app(args : list[str]):
'''Args are : config file path, [--test], [--api].'''
conf_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "conf.json" if not "--test" in args else "test_conf.json"))
conf = Config(conf_path)
conn = db.connect(conf.database)
db.create_tables(conn)
db.set_version(conn)
conn.commit()
conn.close()
if "--api" in args:
app = create_flask_app(conf_path)
app.run(debug=True)
else:
start(conf, conf.database)
def validate_conf_path(filepath, is_test) :
if not os.path.isfile(filepath) :
raise ValueError("Filename doesn't lead to a file")
if is_test and not filepath.startswith("test_"):
raise ValueError("Test launch requires a conf filename beginning with 'test_'.")
return filepath
if __name__ == "__main__":
create_app(sys.argv[1:])