- daemonize IO thread

- add messages, nicer layout to web config editor
workspace
Brendan Howell 5 years ago
parent 5db5495153
commit da32f9a01a

@ -465,7 +465,7 @@ class Bureau(object):
""" """
# start the hardware input handler # start the hardware input handler
io_handler = threading.Thread(target=self._run_io) io_handler = threading.Thread(target=self._run_io, daemon=True)
io_handler.start() io_handler.start()
# register commands and api methods # register commands and api methods
@ -499,7 +499,6 @@ class Bureau(object):
self.log.debug("got method: " + ref) self.log.debug("got method: " + ref)
if (ref in self.commands) or (ref in self.api): if (ref in self.commands) or (ref in self.api):
# TODO: cope with data for calls with no params
if ref in self.api: if ref in self.api:
if data: if data:
data = json.loads(data) data = json.loads(data)

@ -40,9 +40,13 @@ class IhrApp(Bottle):
def bureau_config(self, bureau): def bureau_config(self, bureau):
# parse the config and make it into a form # parse the config and make it into a form
# TODO: add a little html snippet with cfg file docs
templfile = os.path.join(self.tdir, "web_config.html") templfile = os.path.join(self.tdir, "web_config.html")
template = mako.template.Template(filename=templfile) template = mako.template.Template(filename=templfile)
basedir = os.path.expanduser("~/.screenless") basedir = os.path.expanduser("~/.screenless")
msg = ""
if bureau == "mgmt": if bureau == "mgmt":
cfgfile = "mgmt.ini" cfgfile = "mgmt.ini"
mode = "ini" mode = "ini"
@ -54,15 +58,15 @@ class IhrApp(Bottle):
mode = "yaml" mode = "yaml"
cfgfile = os.path.join(basedir, cfgfile) cfgfile = os.path.join(basedir, cfgfile)
if request.method == "POST": if request.method == "POST":
#save all the request.forms stuff to the config with open(cfgfile, "w") as cfg:
# tell the bureau to restart / reload cfg.write(request.forms.get("cfgdata"))
# set our message to be "updated config" # TODO: tell the bureau to restart / reload
print("NOT saving updated ", cfgfile) msg = "Modified config file saved!"
pass
#parse and show the config as a form #parse and show the config as a form
with open(cfgfile) as cfg: with open(cfgfile) as cfg:
cfgdata = cfg.read() cfgdata = cfg.read()
return template.render_unicode(bureau=bureau, cfgfile=cfgfile, mode=mode, cfgdata=cfgdata) return template.render_unicode(msg=msg, bureau=bureau, cfgfile=cfgfile, mode=mode, cfgdata=cfgdata)
def register_bureau(self, bureau): def register_bureau(self, bureau):
self.bureaus.append(bureau) self.bureaus.append(bureau)

@ -4,17 +4,23 @@
<title>Screenless Office - edit ${cfgfile}</title> <title>Screenless Office - edit ${cfgfile}</title>
<style type="text/css" media="screen"> <style type="text/css" media="screen">
#editor { #editor {
position: absolute; height: 40em;
top: 0; width: 80em;
right: 0; }
bottom: 0; #msg {
left: 0; width: 40em;
background-color: pink;
height: 3em;
transition: opacity 3s ease-in-out;
text-align: center;
} }
</style> </style>
</head> </head>
<body> <body>
<h3>The Screenless Office</h3> <h3>The Screenless Office</h3>
<h4> edit config file <em>${cfgfile}</em></h4> <h4> edit config file <em>${cfgfile}</em></h4>
<div id="msg">${msg}</div>
<div><a href="/">← Main</a></div>
<div id="editor">${cfgdata}</div> <div id="editor">${cfgdata}</div>
<form id="cfgform" action="/config/${bureau}" method="post"> <form id="cfgform" action="/config/${bureau}" method="post">
<input type="hidden" value="${cfgdata}" name="cfgdata_field" id="cfgdata_field" /> <input type="hidden" value="${cfgdata}" name="cfgdata_field" id="cfgdata_field" />

Loading…
Cancel
Save