clean up ambiguous or sloppy use of . delimiter

workspace
Brendan Howell 9 years ago
parent 37f6c1cfc3
commit 85438784f8

@ -10,6 +10,7 @@ import textwrap
import threading import threading
import time import time
import lmdb
import zmq import zmq
from mako.template import Template from mako.template import Template
@ -83,6 +84,16 @@ class Bureau(object):
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
self.load_config() 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.context = zmq.Context()
self._recv = self.context.socket(zmq.REP) self._recv = self.context.socket(zmq.REP)
self._recv.bind("ipc://" + self.prefix + ".ipc") self._recv.bind("ipc://" + self.prefix + ".ipc")
@ -112,7 +123,11 @@ class Bureau(object):
returns either empty string, text or a json 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: if data:
message += json.dumps(data) message += json.dumps(data)
sender = self.context.socket(zmq.REQ) sender = self.context.socket(zmq.REQ)
@ -274,9 +289,12 @@ class Bureau(object):
time.sleep(0.05) # don't waste CPU time.sleep(0.05) # don't waste CPU
continue continue
try: try:
print("got message:", msg)
dot = msg.find(".") dot = msg.find(".")
ref = msg[:dot] ref = msg[:dot]
if (dot < len(msg) - 1) and (dot > 0): if (dot < len(msg) - 1) and (dot > 0):
print("msg length:", len(msg))
print("dot at", dot)
data = msg[dot + 1:] data = msg[dot + 1:]
else: else:
data = None data = None

Loading…
Cancel
Save