2018-02-13 02:48:00 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2019-02-20 04:36:43 +00:00
|
|
|
|
2018-02-13 02:48:00 +00:00
|
|
|
from flask import Flask
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
2020-12-21 23:44:26 +00:00
|
|
|
if os.path.exists(os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.local.py")):
|
|
|
|
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.local.py")
|
2018-02-13 02:48:00 +00:00
|
|
|
else:
|
|
|
|
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py")
|
|
|
|
app.config.from_pyfile(config)
|
|
|
|
|
2020-12-21 23:44:26 +00:00
|
|
|
timeout = config.TIMEOUT
|
|
|
|
|
2018-02-13 02:48:00 +00:00
|
|
|
|
|
|
|
def start_websockify(websockify_path, target_file):
|
|
|
|
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE)
|
|
|
|
if not result.stdout:
|
2020-12-21 23:44:26 +00:00
|
|
|
subprocess.call(
|
|
|
|
[
|
|
|
|
websockify_path,
|
|
|
|
'8081',
|
|
|
|
'--token-plugin',
|
|
|
|
'TokenFile',
|
|
|
|
'--token-source',
|
|
|
|
target_file,
|
|
|
|
'-D',
|
|
|
|
],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
)
|
2018-02-13 02:48:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def on_starting(server):
|
2020-12-21 23:44:26 +00:00
|
|
|
start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])
|