-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_release.py
executable file
·64 lines (49 loc) · 1.92 KB
/
run_release.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
from flask import Flask, send_from_directory, jsonify
from gevent.pywsgi import WSGIServer
import sys
import signal
import os
from backend_py.src import Server, ServerOptions
import multiprocessing
import logging
import argparse
logging.getLogger().setLevel(logging.INFO)
def run_frontend(port):
app = Flask(__name__)
FRONTEND_DIR = os.path.abspath('./frontend/dist')
@app.route('/', defaults={'path': 'index.html'})
@app.route('/<path:path>')
def index(path):
return send_from_directory(FRONTEND_DIR, path)
blueos_extension = {
'name': 'dwe_os_2',
'description': 'Web-based driver and software interface for DWE.ai cameras',
'icon': 'mdi-camera-plus',
'company': 'DeepWater Exploration',
'version': '1.0.0',
'webpage': 'https://dwe.ai/products/dwe-os',
'api': 'https://dwe.ai/products/dwe-os'
}
@app.route('/register_service')
def register_service():
return jsonify(blueos_extension)
@app.errorhandler(404)
def not_found(e):
return send_from_directory(FRONTEND_DIR, 'index.html')
logging.info(f'Starting client server on http://0.0.0.0:{port}')
http_server = WSGIServer(('0.0.0.0', port), app, log=None)
http_server.serve_forever()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run the server with parameters')
parser.add_argument('--no-ttyd', action='store_true', help='Disable ttyd server')
parser.add_argument('--port', type=int, default=80, help='Set the port of the server')
args = parser.parse_args()
frontend_thread = multiprocessing.Process(target=run_frontend, args=[args.port])
frontend_thread.start()
def exit_clean(sig, frame):
logging.info('Exiting')
frontend_thread.kill()
sys.exit(0)
signal.signal(signal.SIGINT, exit_clean)
server = Server(server_options=ServerOptions(no_ttyd=args.no_ttyd))
server.serve()