diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 8162811..186d17e 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -10,6 +10,7 @@ import textwrap import threading import time +import lmdb import zmq from mako.template import Template @@ -83,6 +84,16 @@ class Bureau(object): self.config = configparser.ConfigParser() self.load_config() + # setup a dir to store files and data + self.datadir = os.path.join(basepath, self.prefix) + if not os.path.exists(self.datadir): + os.mkdir(self.datadir) + + # set up a basic key-value store with LMDB - max 10 sub-dbs + # if a bureau needs more then just import lmdb and roll your own + dbfile = os.path.join(self.datadir, self.prefix + ".lmdb") + self.dbenv = lmdb.open(dbfile, max_dbs=10) + self.context = zmq.Context() self._recv = self.context.socket(zmq.REP) self._recv.bind("ipc://" + self.prefix + ".ipc") @@ -112,7 +123,11 @@ class Bureau(object): returns either empty string, text or a json object """ - message += "." + # clean up for sloppy offices + message = message.strip() + if not message.endswith("."): + message += "." + if data: message += json.dumps(data) sender = self.context.socket(zmq.REQ) @@ -274,9 +289,12 @@ class Bureau(object): time.sleep(0.05) # don't waste CPU continue try: + print("got message:", msg) dot = msg.find(".") ref = msg[:dot] if (dot < len(msg) - 1) and (dot > 0): + print("msg length:", len(msg)) + print("dot at", dot) data = msg[dot + 1:] else: data = None