49 lines
1.4 KiB
Python
Executable File
49 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import time
|
|
import threading
|
|
import socket
|
|
from pathlib import Path
|
|
from flask import Flask, render_template, request, redirect, jsonify
|
|
|
|
app = Flask(__name__)
|
|
|
|
class Args:
|
|
def __init__(self, name, port='8050', webport='8051'):
|
|
if '.' in name:
|
|
name, port = name.split('.')
|
|
webport = str(int(port) + 1)
|
|
args = dict(
|
|
html = 'common.html',
|
|
svg = 'common.svg',
|
|
css = 'common.css',
|
|
js = 'secop.js',
|
|
)
|
|
common, _, variant = name.partition('_')
|
|
names = [common, name] if variant else [name]
|
|
for name in names:
|
|
for key in list(args):
|
|
print(f'{name}.{key}')
|
|
if (Path('templates') / f'{name}.{key}').is_file():
|
|
print(f'--- {name}.{key}')
|
|
args[key] = f'{name}.{key}'
|
|
hostname = socket.gethostname()
|
|
if '.' not in hostname:
|
|
hostname += '.psi.ch'
|
|
args['wsaddr'] = f'{hostname}:{webport}'
|
|
self.port = int(port)
|
|
self.html = args.pop('html')
|
|
self.args = args
|
|
print(self.html, self.port, self.args)
|
|
|
|
args = Args(*sys.argv[1:])
|
|
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template(f'{args.html}', **args.args)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0", port=args.port, debug=True)
|