-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_api.py
75 lines (62 loc) · 2.24 KB
/
run_api.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
This file is the entry point of flask api. Launch python3 ronoco_vm/run.py to run flask server
"""
import os
from flask import Flask
from flask_cors import CORS
from flask_socketio import SocketIO
from werkzeug.debug import DebuggedApplication
class RunAPI:
"""
Define and setup flask server and ros topic subscriber / publisher for ronoco-vm
"""
def __init__(self):
"""
Launch flask server when RonocoVm is created (this constructor uses SocketIO)
"""
self.app = None
self.create_app()
socketio = SocketIO(self.app, logger=False, cors_allowed_origins='*')
self.setup_app()
# self.socketio.run(host='0.0.0.0', port=8000, debug=True)
socketio.run(self.app, host="0.0.0.0")
def create_app(self, test_config=None):
"""
Build a Flask instance and configure it
:param test_config: path to configuration file (Default : None)
:return: a Flask instance
"""
# create and configure the app
self.app = Flask(__name__, instance_relative_config=True)
self.app.config.from_mapping(
SECRET_KEY='dev',
)
self.app.debug = True
self.app.wsgi_app = DebuggedApplication(self.app.wsgi_app, evalex=True)
if test_config is None:
# load the instance config, if it exists, when not testing
self.app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
self.app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(self.app.instance_path)
except OSError:
pass
def setup_app(self):
"""
Register blueprint in app.
The class attribute "app" must contain an Flask instance
:return: None
"""
import common_cameleon
self.app.register_blueprint(common_cameleon.CommonCameleon().bp)
import stream_cameleon
stream = stream_cameleon.StreamCameleon()
self.app.register_blueprint(stream.bp)
import configure_cameleon
self.app.register_blueprint(stream.configuration.bp)
CORS(self.app)
if __name__ == "__main__":
RunAPI()