From 0833aa2102edd3078ad22459b1920f0e95dca177 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Tue, 19 May 2015 00:47:11 +0200 Subject: [PATCH] update bureau to send and recieve json formatted params for API calls --- screenless/bureau/bureau.py | 13 +++++++++---- screenless/io/dumbkb.py | 16 ---------------- 2 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 screenless/io/dumbkb.py diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 552b302..60bd508 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -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__": diff --git a/screenless/io/dumbkb.py b/screenless/io/dumbkb.py deleted file mode 100644 index 0717ce3..0000000 --- a/screenless/io/dumbkb.py +++ /dev/null @@ -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() -