From 2e52290cdd03374b0158b5742cfbd05ac3822520 Mon Sep 17 00:00:00 2001 From: Thomas Rhoads Date: Tue, 8 Sep 2020 11:10:01 -0400 Subject: [PATCH 1/2] Some additional logging and added CLI abilities. --- oa/core/hub.py | 2 ++ oa/modules/abilities/core.py | 1 + oa/util/repl.py | 24 ++++++++++++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/oa/core/hub.py b/oa/core/hub.py index 2453ffb..e14f6fe 100644 --- a/oa/core/hub.py +++ b/oa/core/hub.py @@ -28,7 +28,9 @@ def run(self): def put(self, part, value): """ Put a message on the wire. """ + _logger.debug(f"PUT Called... {part} <- {value}") if part in self.parts: + _logger.debug("Part specified... putting on the wire.") self.parts[part].wire_in.put(value) diff --git a/oa/modules/abilities/core.py b/oa/modules/abilities/core.py index 0e4edae..1cb949f 100644 --- a/oa/modules/abilities/core.py +++ b/oa/modules/abilities/core.py @@ -58,6 +58,7 @@ def get(part = None, timeout = .1): def put(part, value): """ Put a message on the wire. """ + _logger.debug(f"PUT Called... {part} <- {value}") oa.legacy.hub.parts[part].wire_in.put(value) def empty(part = None): diff --git a/oa/util/repl.py b/oa/util/repl.py index 062617e..daf5205 100644 --- a/oa/util/repl.py +++ b/oa/util/repl.py @@ -1,10 +1,14 @@ import logging +import re _logger = logging.getLogger(__name__) +regex_mind_command = re.compile(r'^(\S+):') def command_loop(hub:object) -> None: """Responsible for maintaining command line interface for OA. Interfaces - textual commands with the hub. + textual commands with the hub. Commands are directed to the OA bus addressed + to the minds by default. Commands can be directed at modules specifically + using the syntax `: ` Args: hub (object): The current instance of hub passed over from oa.__main__.py @@ -18,13 +22,21 @@ def command_loop(hub:object) -> None: while not hub.finished.is_set(): cmd = input("OA> ") + _logger.debug("Raw CLI Command: {}".format(cmd)) if cmd in ['q', 'quit']: hub.finished.set() + break elif cmd in ['h', 'help', '?']: print("Help Stuff") - elif cmd.find(' ') > -1: - p, m = cmd.split(' ', 1) - _logger.debug("{} <- {}".format(p, m)) - hub.put(p, m) + continue + elif regex_mind_command.match(cmd): + # Dircted at a specific module. Extract the module and command. + # Remove initial whitespace if space was given after : + p, m = cmd.split(':', 1) + m = m.lstrip(' ') else: - print("Unrecognized command: {}".format(cmd)) + # Default to send the command to the minds. + p, m = "mind", cmd + + _logger.debug("{} <- {}".format(p, m)) + hub.put(p, m) From 8f9bd9b30c897aaf644a519dbdaf436529744ff4 Mon Sep 17 00:00:00 2001 From: Thomas Rhoads Date: Tue, 8 Sep 2020 11:16:20 -0400 Subject: [PATCH 2/2] Additional PEP8 formatting. --- oa/util/repl.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oa/util/repl.py b/oa/util/repl.py index daf5205..65181c5 100644 --- a/oa/util/repl.py +++ b/oa/util/repl.py @@ -1,10 +1,12 @@ import logging import re -_logger = logging.getLogger(__name__) + +_logger = logging.getLogger(__name__) regex_mind_command = re.compile(r'^(\S+):') -def command_loop(hub:object) -> None: + +def command_loop(hub: object) -> None: """Responsible for maintaining command line interface for OA. Interfaces textual commands with the hub. Commands are directed to the OA bus addressed to the minds by default. Commands can be directed at modules specifically