mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2025-07-03 17:46:24 +00:00
Refactor TerminalCommands
This commit is contained in:
committed by
therealkrispet
parent
ef2ab5d0bf
commit
e50a8732fc
@ -1,33 +1,29 @@
|
||||
import logging
|
||||
from ast import literal_eval
|
||||
|
||||
from tfw.components import MessageSender, TerminalCommands
|
||||
from tfw.builtins import EventHandler, FSMAwareEventHandler, TFWServerUplinkConnector
|
||||
from tfw.components import MessageSender
|
||||
from tfw.builtins import TFWServerUplinkConnector
|
||||
from tfw.builtins import EventHandler, FSMAwareEventHandler, TerminalCommandsEventHandler
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TerminalCallbackEventHandler(EventHandler):
|
||||
class CenatorEventHandler(EventHandler):
|
||||
"""
|
||||
Logs commands executed in terminal to messages and invokes an
|
||||
additional callback function to handle special commands.
|
||||
!! Please remove from production code. !!
|
||||
"""
|
||||
def __init__(self, key, callback):
|
||||
self.callback = callback
|
||||
def __init__(self, key):
|
||||
super().__init__(key)
|
||||
|
||||
def handle_event(self, message):
|
||||
command = message['value']
|
||||
self.cenator(command)
|
||||
self.callback(command)
|
||||
|
||||
def cenator(self, command):
|
||||
LOG.debug('User executed command: "%s"', command)
|
||||
MessageSender(self.server_connector).send('JOHN CENA', f'You\'ve executed "{command}"')
|
||||
|
||||
|
||||
class TestCommands(TerminalCommands):
|
||||
class TestCommandsEventHandler(TerminalCommandsEventHandler):
|
||||
"""
|
||||
Some example commands useful for debugging.
|
||||
!! Please remove from production code !! and inherit your own
|
||||
@ -54,31 +50,6 @@ class TestCommands(TerminalCommands):
|
||||
else:
|
||||
TFWServerUplinkConnector().send_message(literal_eval(args[0]))
|
||||
|
||||
def command_seppuku_tfw(self, *args):
|
||||
"""
|
||||
Restart tfw_server.py and event_handler_main.py.
|
||||
This can speed up development when combined with mounting
|
||||
volumes from host to container.
|
||||
"""
|
||||
seppuku = (
|
||||
'nohup sh -c "supervisorctl restart tfwserver event_handler_main" &> /dev/null & '
|
||||
'clear && echo "Committed seppuku! :)" && sleep infinity'
|
||||
)
|
||||
uplink = TFWServerUplinkConnector()
|
||||
uplink.send_message({
|
||||
'key': 'shell',
|
||||
'data': {
|
||||
'command': 'write',
|
||||
'value': f'{seppuku}\n'
|
||||
}
|
||||
})
|
||||
uplink.send_message({
|
||||
'key': 'dashboard',
|
||||
'data': {
|
||||
'command': 'reloadFrontend'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
class MessageFSMStepsEventHandler(FSMAwareEventHandler):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user