Skip to content

Some additional logging and added CLI abilities. #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions oa/core/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
1 change: 1 addition & 0 deletions oa/modules/abilities/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
28 changes: 21 additions & 7 deletions oa/util/repl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import logging
import re


_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.
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 `<module>: <command>`

Args:
hub (object): The current instance of hub passed over from oa.__main__.py
Expand All @@ -18,13 +24,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 <module>:
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)