From 933e90e189576f9c33751532d9dbc58faec14596 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 26 Jan 2020 21:50:14 +0100 Subject: [PATCH] Initial leyk remote client --- .gitignore | 4 +++ .gitmodules | 18 ++++++++++++++ .project | 17 +++++++++++++ .pydevproject | 8 ++++++ protocol | 1 + report | 1 + socket_protocol | 1 + stringtools | 1 + task | 1 + tcp_client.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ tcp_socket | 1 + 11 files changed, 119 insertions(+) create mode 100644 .gitmodules create mode 100644 .project create mode 100644 .pydevproject create mode 160000 protocol create mode 160000 report create mode 160000 socket_protocol create mode 160000 stringtools create mode 160000 task create mode 100644 tcp_client.py create mode 160000 tcp_socket diff --git a/.gitignore b/.gitignore index e61bca2..5d806c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +config.py +*.warn +*.log + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9c3a119 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,18 @@ +[submodule "protocol"] + path = protocol + url = https://git.mount-mockery.de/application/leyk_protocol +[submodule "report"] + path = report + url = https://git.mount-mockery.de/pylib/report.git +[submodule "socket_protocol"] + path = socket_protocol + url = https://git.mount-mockery.de/pylib/socket_protocol.git +[submodule "stringtools"] + path = stringtools + url = https://git.mount-mockery.de/pylib/stringtools.git +[submodule "task"] + path = task + url = https://git.mount-mockery.de/pylib/task.git +[submodule "tcp_socket"] + path = tcp_socket + url = https://git.mount-mockery.de/pylib/tcp_socket.git diff --git a/.project b/.project new file mode 100644 index 0000000..d620ad4 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + leyk + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..aa7a29a --- /dev/null +++ b/.pydevproject @@ -0,0 +1,8 @@ + + + + /${PROJECT_DIR_NAME} + + python interpreter + Default + diff --git a/protocol b/protocol new file mode 160000 index 0000000..6ac1b58 --- /dev/null +++ b/protocol @@ -0,0 +1 @@ +Subproject commit 6ac1b584fb53aeb58c1b9809fff306a56dd32400 diff --git a/report b/report new file mode 160000 index 0000000..98fea3a --- /dev/null +++ b/report @@ -0,0 +1 @@ +Subproject commit 98fea3a4d45ba906d08a8ebc90525fb3592f06be diff --git a/socket_protocol b/socket_protocol new file mode 160000 index 0000000..127ef51 --- /dev/null +++ b/socket_protocol @@ -0,0 +1 @@ +Subproject commit 127ef51719f2fdbc6699f7e0751f9d92f6773f0f diff --git a/stringtools b/stringtools new file mode 160000 index 0000000..b86248c --- /dev/null +++ b/stringtools @@ -0,0 +1 @@ +Subproject commit b86248c1a3a3456e489e007857271106e1ecf090 diff --git a/task b/task new file mode 160000 index 0000000..d3fbc59 --- /dev/null +++ b/task @@ -0,0 +1 @@ +Subproject commit d3fbc5934051ab165723ca37e8f02596329f174a diff --git a/tcp_client.py b/tcp_client.py new file mode 100644 index 0000000..daf2344 --- /dev/null +++ b/tcp_client.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +import config +import os +import protocol +import report +import sys +import tcp_socket + + +def help_msg(): + print(""""Possible commands are: + * q[uit] + * auto[matic] + * man[ual] + * mode + * state + * get [all,bakehose,bakery,mill,reesehouse,ploenlein] + * set [all,bakehose,bakery,mill,reesehouse,ploenlein] [on,off]""") + + + +if __name__ == '__main__': + report.appLoggingConfigure(os.path.dirname(__file__), 'logfile', config.loggers) + c = tcp_socket.tcp_client_stp(config.server_ip, config.server_port) + prot = protocol.my_client_protocol(c, secret=config.secret) + target_dict = { + 'bakehouse': [prot.DID_BAKE_HOUSE, ], + 'bakery': [prot.DID_BAKERY, ], + 'mill': [prot.DID_MILL, ], + 'ploenlein': [prot.DID_PLOENLEIN, ], + 'reesehouse': [prot.DID_REESE_HOUSE, ], + 'all': [prot.DID_BAKE_HOUSE, prot.DID_BAKERY, prot.DID_MILL, prot.DID_PLOENLEIN, prot.DID_REESE_HOUSE] + } + if prot.authentificate(): + help_msg() + cmd = None + while cmd not in ["q", "quit"]: + cmd = sys.stdin.readline() + cmd = cmd.lower().strip('\n') + if cmd == 'help': + help_msg() + elif cmd in ["auto", "automatic"]: + prot.send(prot.SID_EXECUTE_REQUEST, prot.DID_MODE, 'automatic') + elif cmd in ["man", "manual"]: + prot.send(prot.SID_EXECUTE_REQUEST, prot.DID_MODE, 'manual') + elif cmd == "mode": + prot.send(prot.SID_READ_REQUEST, prot.DID_MODE, None) + elif cmd == "state": + prot.send(prot.SID_READ_REQUEST, prot.DID_STATE, None) + elif cmd.startswith('get '): + target = target_dict.get(cmd.split(' ')[1]) + if target is not None: + for t in target: + prot.send(prot.SID_READ_REQUEST, t, None) + elif cmd.startswith('set '): + target = target_dict.get(cmd.split(' ')[1]) + try: + state = {'on': True, 'off': False}.get(cmd.split(' ')[2]) + except IndexError: + state = None + if target is not None and state is not None: + for t in target: + prot.send(prot.SID_EXECUTE_REQUEST, t, state) + c.close() diff --git a/tcp_socket b/tcp_socket new file mode 160000 index 0000000..62f13e2 --- /dev/null +++ b/tcp_socket @@ -0,0 +1 @@ +Subproject commit 62f13e2d878b09b81d094c2f77dbd830d72be2c7