first try at web editor

workspace
Brendan Howell 5 years ago
parent c2addd9cbd
commit 41febd1038

@ -3,11 +3,13 @@ import os
import signal
import socket
import subprocess
import threading
import kode256
from lxml import etree
from bureau import Bureau, add_command, add_api
import ihrweb
class InhumanResources(Bureau):
@ -24,6 +26,11 @@ class InhumanResources(Bureau):
def __init__(self):
Bureau.__init__(self)
self.menu = {}
self.webapp = ihrweb.IhrApp()
webargs = { "host": "0.0.0.0", "port": 8000 }
self.webthread = threading.Thread(target=self.webapp.run,
kwargs=webargs, daemon=True)
self.webthread.start()
# update_commands(self)
@add_api("addbureau", "Register Bureau")
@ -40,6 +47,7 @@ class InhumanResources(Bureau):
name = data["name"]
prefix = data["prefix"]
desc = data["desc"]
self.webapp.register_bureau(prefix)
except KeyError as e:
print("cannot add invalid bureau:", str(e))
return str(e)

@ -0,0 +1,60 @@
# this is a web interface for simple edits to configuration or editing data
# for particular bureaus
import configparser
import os
from bottle import Bottle, request
class IhrApp(Bottle):
def __init__(self):
super(IhrApp, self).__init__()
self.name = "IHR App"
self.route("/", callback=self.index)
self.route("/config/<bureau>", callback=self.config)
self.route("/config/<bureau>", callback=self.config, method="POST")
self.bureaus = []
def index(self):
# return a list of active bureaus with links
# TODO: allow (de)activation of non-essential bureaus
out = """
<h3>The Screenless Office</h3>
<h4><em>Config Manager</em></h4>
<ul>
"""
for bureau in self.bureaus:
out += '<li><a href="/config/"' + bureau + '"></li>\n'
out += "</ul>"
return out
def config(self, bureau):
# parse the config and make it into a form
out = "<h3>config file for " + bureau + "</h3>\n"
basedir = os.path.expanduser("~/.screenless")
if bureau == "mgmt":
cfgfile = "mgmt.ini"
elif bureau == "printers":
cfgfile = printers.cfg
else:
cfgfile = bureau + ".yml"
cfgfile = os.path.join(basedir, cfgfile)
if request.method == "POST":
#save all the request.forms stuff to the config
# tell the bureau to restart / reload
# set our message to be "updated config"
print("NOT saving updated ", cfgfile)
pass
#parse and show the config as a form
with open(cfgfile) as cfg:
out += cfg.read()
return out
def register_bureau(self, bureau):
self.bureaus.append(bureau)
def register_crud(self, data):
# adds callbacks for crud operations on a database
pass
Loading…
Cancel
Save