You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.0 KiB
Python

import json
import subprocess
import code128
from bureau import Bureau, add_command, add_api
class InhumanResources(Bureau):
"""
This is a core functional bureau of the Screenless office it keeps track
of all published methods provided by all other bureaus and can print
the menu for the whole system or an individual item
"""
name = "Inhuman Resources"
prefix = "IR"
version = 0
def __init__(self):
Bureau.__init__(self)
self.menu = {}
# update_commands(self)
@add_api("addbureau", "Register Bureau")
def add_bureau(self, data):
"""
Register Bureau with Inhuman Resources
data = { prefix: "IR",
name: "Inhuman Resources",
desc: "Keep track of public resources provided by bureaus"
}
"""
try:
name = data["name"]
prefix = data["prefix"]
desc = data["desc"]
except KeyError as e:
print("cannot add invalid bureau:", str(e))
return str(e)
print("added menu")
self.menu[prefix] = {"name": name,
"desc": desc,
"commands": {},
"apis": {}}
@add_api("addcommand", "Register Command")
def add_cmd(self, data):
try:
prefix = data["prefix"]
cmd = data["cmd"]
cmdname = data["cmdname"]
desc = data["desc"]
barcode = code128.svg(prefix + cmd + ".")
except KeyError as e:
print("cannot add invalid command:", str(e))
return
if prefix not in self.menu:
# TODO: this should throw some kind of error message/log
print("error: cannot add command ", cmd, "to non-existent prefix",
prefix)
else:
self.menu[prefix]["commands"][cmd] = {"name": cmdname,
"desc": desc,
"barcode": barcode}
@add_api("addapi", "Register API Method")
def add_api_method(self, data):
try:
prefix = data["prefix"]
cmd = data["api"]
cmdname = data["apiname"]
desc = data["desc"]
except KeyError as e:
print("cannot add invalid command:", str(e))
return
if prefix not in self.menu:
# TODO: this should throw some kind of error message/log
print("error: cannot add command ", cmd, "to non-existent prefix",
prefix)
else:
self.menu[prefix]["apis"][cmd] = {"name": cmdname,
"desc": desc}
@add_command("menu", "Print Menu")
def print_menu(self):
"""
Prints the menu of commands for all operational bureaus.
"""
self.print_full("menu.html", menu=self.menu)
@add_command("update", "Restructure Organization")
def update(self):
"""
Restructure the organization. This may include firing, hiring,
refinancing and organizational changes. This will update the
Office to the latest software but it may be disruptive to your
current personal and social situation. After pulling the latest
updates, all bureaus other than management will be restarted.
"""
subprocess.call("git pull")
self.restart()
@add_command("restart", "Furlough")
def restart(self):
"""
Send the entire organization on a very short unpaid vacation. This
will restart all bureaus, so it may cause disruption, loss of work
and other psycho-social side effects of a loss of state. It may
also help restore a messed up office to normal operation.
"""
# TODO: find the PID of mgmt and send it a HUP signal
pass
def main():
hr = InhumanResources()
hr.run()
if __name__ == "__main__":
hr = InhumanResources()
hr.run()