diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 4061681..09239e5 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -88,6 +88,7 @@ class Bureau(object): # setup log file # TODO: make log level globally and bureau-specific via config + # TODO: custom handler to print errors to small printer logfile = os.path.join(basepath, self.prefix + ".log") logging.basicConfig(filename=logfile, level=logging.DEBUG) self.log = logging.getLogger(self.prefix) @@ -110,7 +111,7 @@ class Bureau(object): self._recv.bind("ipc://" + self.prefix + ".ipc") self.log.debug("bureau " + self.name + " waiting for messages") self.log.debug("commands: ") - self.log.debug(self.commands) + self.log.debug(str(self.commands)) def load_config(self): """ @@ -210,8 +211,8 @@ class Bureau(object): self.send("IR", "addapi", api_detail) self.log.debug("registered:") - self.log.debug(self.commands) - self.log.debug(self.api) + self.log.debug(str(self.commands)) + self.log.debug(str(self.api)) def print_full(self, template, **kwargs): """print a full page (A4) document """ @@ -240,7 +241,7 @@ class Bureau(object): # TODO: make paper size a config variable pdfpath = tempfile.mkstemp(".pdf")[1] - self.log.debug("rendering with: ", self.html2pdf + htmlpath + " " + pdfpath) + self.log.debug("rendering with: " + self.html2pdf + htmlpath + " " + pdfpath) subprocess.call(self.html2pdf + htmlpath + " " + pdfpath + " A4 1920px", shell=True) subprocess.call("lpr " + pdfpath, shell=True) @@ -314,12 +315,12 @@ class Bureau(object): time.sleep(0.05) # don't waste CPU continue try: - self.log.debug("got message:", msg) + self.log.debug("got message:" + msg) dot = msg.find(".") ref = msg[:dot] if (dot < len(msg) - 1) and (dot > 0): - self.log.debug("msg length:", len(msg)) - self.log.debug("dot at", dot) + self.log.debug("msg length: %d", len(msg)) + self.log.debug("dot at %d", dot) # TODO: maybe trim off the trailing "." for convenience data = msg[dot + 1:] # data = str(data) # force to be a string @@ -327,9 +328,9 @@ class Bureau(object): data = None self.log.debug("data: " + str(data)) except IndexError as err: - self.log.warning("invalid message: ", err) + self.log.warning("invalid message: %s", err) continue - self.log.debug(("got method: " + ref)) + self.log.debug("got method: " + ref) if (ref in self.commands) or (ref in self.api): # catch TypeErrors for case of bogus params @@ -354,7 +355,7 @@ class Bureau(object): # print("invalid data for command '{}': {}".format(ref, data)) # self._recv.send_unicode("Error. Invalid or missing data.") except KeyError as err: - self.log.warning(err) + self.log.warning(str(err)) self.log.warning("You are calling a command as an API or vice-versa.") self._recv.send_unicode( "Error. Command called as API or API as command.") diff --git a/screenless/bureau/ihr/ihr.py b/screenless/bureau/ihr/ihr.py index 9280040..6576f4e 100644 --- a/screenless/bureau/ihr/ihr.py +++ b/screenless/bureau/ihr/ihr.py @@ -1,5 +1,6 @@ import json -import os.path +import os +import signal import subprocess import code128 @@ -133,7 +134,9 @@ class InhumanResources(Bureau): also help restore a messed up office to normal operation. """ # TODO: find the PID of mgmt and send it a HUP signal - pass + with open("mgmt.pid") as pfile: + pid = int(pfile.read()) + os.kill(pid, signal.SIGHUP) def main(): diff --git a/screenless/mgmt.py b/screenless/mgmt.py index 033bbd7..d370e61 100644 --- a/screenless/mgmt.py +++ b/screenless/mgmt.py @@ -74,6 +74,9 @@ class Management: main loop for Management, will restart crashed bureaus and reload everything when sent a SIGHUP """ + with open("mgmt.pid", "w") as pfile: + pfile.write(str(os.getpid())) + signal.signal(signal.SIGHUP, self.reload) self._start_bureaus()