From 56bd5a4b750a52f753ad8fc0ca63ae15b57f8517 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 10 Aug 2019 23:00:45 +0200 Subject: Stop using guacamole for the ctl command --- README.rst | 1 - mypy.ini | 3 --- pyapd/ctl_client.py | 14 ++++++++++---- pyapdctl | 25 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100755 pyapdctl diff --git a/README.rst b/README.rst index ceaf2a5..c9d3913 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,6 @@ explicitely. * `Python3 ` >= 3.7 * `Tornado `_ * `ruamel.yaml `_ >= 0.15 -* `guacamole ` License ======= diff --git a/mypy.ini b/mypy.ini index 2db00c6..4447f48 100644 --- a/mypy.ini +++ b/mypy.ini @@ -5,6 +5,3 @@ ignore_missing_imports = True [mypy-tornado.*] ignore_missing_imports = True - -[mypy-guacamole.*] -ignore_missing_imports = True diff --git a/pyapd/ctl_client.py b/pyapd/ctl_client.py index 8c692f9..d788623 100644 --- a/pyapd/ctl_client.py +++ b/pyapd/ctl_client.py @@ -1,23 +1,29 @@ import json import socket -import guacamole +class ClientCommand(): + help = '' + + def register_arguments(self, parser): + pass -class ClientCommand(guacamole.Command): def send_command(self, cmd): print("Sending command", cmd) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(self.config.ctl_socket) s.send(json.dumps(cmd).encode()) + def invoked(self): + pass + class Ping(ClientCommand): def get_command(self): return {"command": "ping"} - def invoked(self, ctx): - print(self.get_command) + def invoked(self): + print(self.get_command()) class AddObject(ClientCommand): diff --git a/pyapdctl b/pyapdctl new file mode 100755 index 0000000..ead5085 --- /dev/null +++ b/pyapdctl @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import argparse + +from pyapd import ctl_client, config + + +class Client(): + sub_commands = ( + ('ping', ctl_client.Ping()), + ('add_object', ctl_client.AddObject()), + ) + + def main(self): + self.parser = argparse.ArgumentParser() + self.subparsers = self.parser.add_subparsers() + for name, sub in self.sub_commands: + s_parser = self.subparsers.add_parser(name, help=sub.help) + sub.register_arguments(s_parser) + s_parser.set_defaults(func=sub.invoked) + self.args = self.parser.parse_args() + self.args.func(self.args) + +if __name__ == "__main__": + Client().main() -- cgit v1.2.3