-
Notifications
You must be signed in to change notification settings - Fork 1
/
rl_run.py
executable file
·53 lines (44 loc) · 1.45 KB
/
rl_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask
from flask_cors import CORS
from backend.config import Config
from backend.endpoints.device import device_bp
from backend.endpoints.master import master_bp
from backend.endpoints.shared import shared_bp
from backend.instance import Instance
from backend.led_controller import LedController
from backend.logger import logger
from backend.system import System
def run():
app = Flask(__name__)
CORS(app)
app.static_folder = f"{app.root_path}/frontend"
app.register_blueprint(shared_bp)
if Instance.is_master():
logger.info("Initializing in master mode")
app.register_blueprint(master_bp)
else:
logger.info("Initializing in device mode")
app.register_blueprint(device_bp)
debug_str = ' in debug mode' if Config.get_value('debug') else ''
logger.info(
f"Running app{debug_str}..."
)
try:
System.check_for_update()
led_controller = LedController()
led_controller.load_preset('idle')
app.run(
debug=Config.get_value('debug'),
port=Instance.get_server_port(),
host="0.0.0.0",
threaded=True,
use_reloader=Config.get_value('debug')
)
except Exception:
logger.exception("Exception running app!")
except KeyboardInterrupt:
logger.info("Termination due to KeyboardInterrupt.")
finally:
led_controller.off()
if __name__ == "__main__":
run()