mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-12-05 02:21:31 +00:00
Fix event handler types and sendmessage command
This commit is contained in:
parent
620f6aa643
commit
054d52b5fa
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from ast import literal_eval
|
from json import loads, JSONDecodeError
|
||||||
|
|
||||||
from tfw.components.frontend import MessageSender
|
from tfw.components.frontend import MessageSender
|
||||||
from tfw.components.terminal import TerminalCommandsHandler
|
from tfw.components.terminal import TerminalCommandsHandler
|
||||||
@ -21,16 +21,16 @@ class TestCommandsHandler(TerminalCommandsHandler):
|
|||||||
# pylint: disable=unused-argument,attribute-defined-outside-init,no-self-use
|
# pylint: disable=unused-argument,attribute-defined-outside-init,no-self-use
|
||||||
def command_sendmessage(self, *args):
|
def command_sendmessage(self, *args):
|
||||||
if not args:
|
if not args:
|
||||||
message_template = """'{"key": "", "data": {"command": ""}}'"""
|
message_template = """'{"key": ""}'"""
|
||||||
TFWUplinkConnector().send_message({
|
TFWUplinkConnector().send_message({
|
||||||
'key': 'shell',
|
'key': 'terminal.write',
|
||||||
'data': {
|
'command': f'sendmessage {message_template}'
|
||||||
'command': 'write',
|
|
||||||
'value': f'sendmessage {message_template}'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
TFWUplinkConnector().send_message(literal_eval(args[0]))
|
try:
|
||||||
|
TFWUplinkConnector().send_message(loads(args[0]))
|
||||||
|
except JSONDecodeError:
|
||||||
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', args[0])
|
||||||
|
|
||||||
|
|
||||||
def messageFSMStepsHandler(message, connector):
|
def messageFSMStepsHandler(message, connector):
|
||||||
|
@ -37,7 +37,7 @@ def main():
|
|||||||
ide_eh = eh_factory.build(IdeHandler(
|
ide_eh = eh_factory.build(IdeHandler(
|
||||||
patterns=['/home/user/workdir/*', '/srv/webservice/user_ops.py']
|
patterns=['/home/user/workdir/*', '/srv/webservice/user_ops.py']
|
||||||
), event_handler_type=ControlEventHandler)
|
), event_handler_type=ControlEventHandler)
|
||||||
deploy_eh = eh_factory.build(DeployHandler(), event_handler_type=ControlEventHandler)
|
deploy_eh = eh_factory.build(DeployHandler())
|
||||||
# Web shell backend
|
# Web shell backend
|
||||||
terminal_eh = eh_factory.build(TerminalHandler(
|
terminal_eh = eh_factory.build(TerminalHandler(
|
||||||
port=TFWENV.TERMINADO_PORT,
|
port=TFWENV.TERMINADO_PORT,
|
||||||
@ -59,11 +59,11 @@ def main():
|
|||||||
frontend_eh = eh_factory.build(FrontendProxyHandler(), event_handler_type=ControlEventHandler)
|
frontend_eh = eh_factory.build(FrontendProxyHandler(), event_handler_type=ControlEventHandler)
|
||||||
message_queue_eh = eh_factory.build(MessageQueueHandler(25), event_handler_type=ControlEventHandler)
|
message_queue_eh = eh_factory.build(MessageQueueHandler(25), event_handler_type=ControlEventHandler)
|
||||||
# Writes live logs to console on frontend
|
# Writes live logs to console on frontend
|
||||||
console_logs_eh = eh_factory.build(ConsoleLogsHandler(stream='stdout'), event_handler_type=ControlEventHandler)
|
console_logs_eh = eh_factory.build(ConsoleLogsHandler(stream='stdout'))
|
||||||
|
|
||||||
# Replace these with your custom event handlers
|
# Replace these with your custom event handlers
|
||||||
# Echoes executed commands to messages
|
# Echoes executed commands to messages
|
||||||
cenator_eh = eh_factory.build(CenatorHandler(), event_handler_type=ControlEventHandler)
|
cenator_eh = eh_factory.build(CenatorHandler())
|
||||||
# Echoes FSM steps
|
# Echoes FSM steps
|
||||||
message_fsm_steps_eh = eh_factory.build(
|
message_fsm_steps_eh = eh_factory.build(
|
||||||
messageFSMStepsHandler,
|
messageFSMStepsHandler,
|
||||||
@ -72,7 +72,7 @@ def main():
|
|||||||
# Catches special commands
|
# Catches special commands
|
||||||
commands_eh = eh_factory.build(TestCommandsHandler(
|
commands_eh = eh_factory.build(TestCommandsHandler(
|
||||||
bashrc=f'/home/{TAOENV.USER}/.bashrc'
|
bashrc=f'/home/{TAOENV.USER}/.bashrc'
|
||||||
), event_handler_type=ControlEventHandler)
|
))
|
||||||
|
|
||||||
setup_signal_handlers()
|
setup_signal_handlers()
|
||||||
IOLoop.current().start()
|
IOLoop.current().start()
|
||||||
|
Loading…
Reference in New Issue
Block a user