Improved webinterface
This commit is contained in:
37
main.py
37
main.py
@@ -4,7 +4,8 @@ import os
|
||||
import serial
|
||||
import threading
|
||||
import json
|
||||
from bottle import route, run
|
||||
import bottle
|
||||
from bottle import route, run, request, post
|
||||
import time
|
||||
import sys
|
||||
import signal
|
||||
@@ -238,8 +239,7 @@ class AppRunner(threading.Thread):
|
||||
if self.currentApp in self.persistent_apps.keys():
|
||||
self.app = self.persistent_apps[self.currentApp]
|
||||
else:
|
||||
persistent = ("persistent" in config.Apps[self.requestedApp].keys() and
|
||||
config.Apps[self.requestedApp]["persistent"])
|
||||
persistent = config.Apps[self.requestedApp]["persistent"]
|
||||
|
||||
logging.info("Starting app "+config.Apps[self.requestedApp]["name"])
|
||||
cmd = config.Apps[self.requestedApp]["cmd"]
|
||||
@@ -277,6 +277,14 @@ class AppRunner(threading.Thread):
|
||||
|
||||
|
||||
|
||||
|
||||
#normalize config
|
||||
for app in config.Apps:
|
||||
if "persistent" not in app.keys():
|
||||
app["persistent"] = False
|
||||
if "guiname" not in app.keys():
|
||||
app["guiname"] = app["name"]
|
||||
|
||||
runner = AppRunner()
|
||||
runner.start()
|
||||
|
||||
@@ -284,17 +292,31 @@ runner.start()
|
||||
def apps_list():
|
||||
s = []
|
||||
for app in config.Apps:
|
||||
s.append(app["name"])
|
||||
s.append({
|
||||
"name": app["name"],
|
||||
"guiname": app["guiname"],
|
||||
"persistent": app["persistent"],
|
||||
})
|
||||
return json.dumps(s)
|
||||
|
||||
@route("/apps/start/<name>")
|
||||
def apps_start(name):
|
||||
def apps_start_param(name):
|
||||
for i in range(len(config.Apps)):
|
||||
if config.Apps[i]["name"] == name:
|
||||
runner.requestApp(i)
|
||||
return "ok"
|
||||
return "not_found"
|
||||
|
||||
@post("/apps/start/<name>")
|
||||
def apps_start_post(name):
|
||||
param = request.forms.get('param')
|
||||
for i in range(len(config.Apps)):
|
||||
if config.Apps[i]["name"] == name:
|
||||
runner.requestApp(i, param)
|
||||
return "ok"
|
||||
return "not_found"
|
||||
|
||||
|
||||
@route("/apps/start/<name>/<param>")
|
||||
def apps_start(name, param):
|
||||
for i in range(len(config.Apps)):
|
||||
@@ -315,8 +337,9 @@ def apps_running():
|
||||
|
||||
@route("/")
|
||||
def index():
|
||||
return open("html/index.html").read()
|
||||
return bottle.static_file("index.html", root='html')
|
||||
#return open("html/index.html").read()
|
||||
|
||||
run(host="0.0.0.0", port=8000)
|
||||
run(host=config.WebHost, port=config.WebPort)
|
||||
running = False
|
||||
runner.join()
|
||||
|
Reference in New Issue
Block a user