diff --git a/screenless/bureau/ihr/ihr.py b/screenless/bureau/ihr/ihr.py index ea0d3b6..3a2fa69 100644 --- a/screenless/bureau/ihr/ihr.py +++ b/screenless/bureau/ihr/ihr.py @@ -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) diff --git a/screenless/bureau/ihr/ihrweb.py b/screenless/bureau/ihr/ihrweb.py new file mode 100644 index 0000000..058fdfa --- /dev/null +++ b/screenless/bureau/ihr/ihrweb.py @@ -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/", callback=self.config) + self.route("/config/", 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 = """ +

The Screenless Office

+

Config Manager

+ " + + return out + + def config(self, bureau): + # parse the config and make it into a form + out = "

config file for " + bureau + "

\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 +