update bureau to send and recieve json formatted params for API calls

workspace
Brendan Howell 10 years ago
parent 7ac0fc8f3f
commit 0833aa2102

@ -68,7 +68,9 @@ class Bureau:
print("commands: ")
print(self.commands)
def send(self, message):
def send(self, message, data=None):
if data:
message += json.dumps(data)
self._send.send_string(message)
def _publish_methods(self):
@ -166,14 +168,14 @@ class Bureau:
dot = msg.find(".")
ref = msg[2:dot]
if (dot < len(msg) - 1) and (dot > 0):
data = msg[dot + 1:]
data = json.loads(msg[dot + 1:])
else:
data = None
print("data: " + str(data))
except IndexError as e:
print("invalid message: ", e)
continue
print(("got command: " + ref))
print(("got method: " + ref))
if (ref in self.commands) or (ref in self.api):
# catch TypeErrors for case of bogus params
@ -185,8 +187,11 @@ class Bureau:
except TypeError as e:
print(e)
print("invalid data for command '{}': {}".format(ref, data))
except KeyError as e:
print(e)
print("You are calling a command as an API or vice-versa.")
else:
print("error! object not found")
print("error! Command/API %s not found", ref)
if __name__ == "__main__":

@ -1,16 +0,0 @@
# dumb raw input reader for keyboard / barcode scanner
# TODO: switch this to using evdev - need to sort out permissions
import sys
#from evdev import InputDevice, list_devices
#devices = map(InputDevice, list_devices())
def main():
while True:
cmd = raw_input()
if __name__ == '__main__':
main()
Loading…
Cancel
Save