diff options
| author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-08-10 23:00:45 +0200 | 
|---|---|---|
| committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-08-10 23:00:45 +0200 | 
| commit | 56bd5a4b750a52f753ad8fc0ca63ae15b57f8517 (patch) | |
| tree | ada1c51f907ef48603cf7013c2bb054365c734ea | |
| parent | 7c56ff408032dba4c88e57584a483657c1ef7278 (diff) | |
| -rw-r--r-- | README.rst | 1 | ||||
| -rw-r--r-- | mypy.ini | 3 | ||||
| -rw-r--r-- | pyapd/ctl_client.py | 14 | ||||
| -rwxr-xr-x | pyapdctl | 25 | 
4 files changed, 35 insertions, 8 deletions
| @@ -21,7 +21,6 @@ explicitely.  * `Python3 <https://www.python.org/>` >= 3.7  * `Tornado <https://www.tornadoweb.org>`_  * `ruamel.yaml <https://bitbucket.org/ruamel/yaml>`_ >= 0.15 -* `guacamole <https://github.com/zyga/guacamole/>`  License  ======= @@ -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() | 
