|
|
|
@ -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.")
|
|
|
|
|