From 054d52b5fa05cac2d1d48abbe325ccde2e17920a Mon Sep 17 00:00:00 2001 From: "R. Richard" Date: Mon, 26 Aug 2019 14:46:21 +0200 Subject: [PATCH] Fix event handler types and sendmessage command --- solvable/src/custom_handlers.py | 16 ++++++++-------- solvable/src/event_handler_main.py | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/solvable/src/custom_handlers.py b/solvable/src/custom_handlers.py index bf34752..1d022fb 100644 --- a/solvable/src/custom_handlers.py +++ b/solvable/src/custom_handlers.py @@ -1,5 +1,5 @@ import logging -from ast import literal_eval +from json import loads, JSONDecodeError from tfw.components.frontend import MessageSender from tfw.components.terminal import TerminalCommandsHandler @@ -21,16 +21,16 @@ class TestCommandsHandler(TerminalCommandsHandler): # pylint: disable=unused-argument,attribute-defined-outside-init,no-self-use def command_sendmessage(self, *args): if not args: - message_template = """'{"key": "", "data": {"command": ""}}'""" + message_template = """'{"key": ""}'""" TFWUplinkConnector().send_message({ - 'key': 'shell', - 'data': { - 'command': 'write', - 'value': f'sendmessage {message_template}' - } + 'key': 'terminal.write', + 'command': f'sendmessage {message_template}' }) 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): diff --git a/solvable/src/event_handler_main.py b/solvable/src/event_handler_main.py index 53acd3c..0a4a0d0 100644 --- a/solvable/src/event_handler_main.py +++ b/solvable/src/event_handler_main.py @@ -37,7 +37,7 @@ def main(): ide_eh = eh_factory.build(IdeHandler( patterns=['/home/user/workdir/*', '/srv/webservice/user_ops.py'] ), event_handler_type=ControlEventHandler) - deploy_eh = eh_factory.build(DeployHandler(), event_handler_type=ControlEventHandler) + deploy_eh = eh_factory.build(DeployHandler()) # Web shell backend terminal_eh = eh_factory.build(TerminalHandler( port=TFWENV.TERMINADO_PORT, @@ -59,11 +59,11 @@ def main(): frontend_eh = eh_factory.build(FrontendProxyHandler(), event_handler_type=ControlEventHandler) message_queue_eh = eh_factory.build(MessageQueueHandler(25), event_handler_type=ControlEventHandler) # 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 # Echoes executed commands to messages - cenator_eh = eh_factory.build(CenatorHandler(), event_handler_type=ControlEventHandler) + cenator_eh = eh_factory.build(CenatorHandler()) # Echoes FSM steps message_fsm_steps_eh = eh_factory.build( messageFSMStepsHandler, @@ -72,7 +72,7 @@ def main(): # Catches special commands commands_eh = eh_factory.build(TestCommandsHandler( bashrc=f'/home/{TAOENV.USER}/.bashrc' - ), event_handler_type=ControlEventHandler) + )) setup_signal_handlers() IOLoop.current().start()