From af1a6261cc91a73274a902a791f4b398dc077408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 8 Mar 2018 16:11:43 +0100 Subject: [PATCH] Refactor naming conventions: data_json -> message in TFW EventHandlers --- .../components/process_managing_event_handler.py | 16 ++++++++-------- lib/tfw/components/source_code_event_handler.py | 10 +++++----- lib/tfw/components/terminado_event_handler.py | 10 +++++----- lib/tfw/event_handler_base.py | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 45e2cdb..5f58648 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -35,15 +35,15 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): return wrapper @_with_monitor_paused - def handle_event(self, key, data_json): + def handle_event(self, key, message): try: - data = data_json['data'] + data = message['data'] self.processmanager(data['command'], data['process_name']) - return data_json + return message except KeyError: - log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) + log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) except SupervisorFault as fault: - data_json['data']['error'] = fault.faultString - data_json['data']['log'] = self.processmanager.read_log(data_json['data']['process_name']) - log.debug('Failed to execute command on process: {}'.format(data_json)) - return data_json + message['data']['error'] = fault.faultString + message['data']['log'] = self.processmanager.read_log(message['data']['process_name']) + log.debug('Failed to execute command on process: {}'.format(message)) + return message diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index 003264a..c7269d0 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -83,14 +83,14 @@ class SourceCodeEventHandler(TriggerlessEventHandler): data['filename'] = self.filemanager.filename data['files'] = self.filemanager.files - def handle_event(self, key, data_json): + def handle_event(self, key, message): try: - data = data_json['data'] - data_json['data'] = self.commands[data['command']](data) + data = message['data'] + message['data'] = self.commands[data['command']](data) self.attach_fileinfo(data) - return data_json + return message except KeyError: - log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) + log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) def cleanup(self): self.monitor.stop() diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index 649f823..6e1b1b5 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -21,13 +21,13 @@ class TerminadoEventHandler(TriggerlessEventHandler): def historymonitor(self): return self._historymonitor - def handle_event(self, key, data_json): - log.debug('TerminadoEventHandler received event: {}'.format(data_json)) + def handle_event(self, key, message): + log.debug('TerminadoEventHandler received event: {}'.format(message)) try: - data_json['data'] = self.commands[data_json['data']['command']](data_json['data']) - return data_json + message['data'] = self.commands[message['data']['command']](message['data']) + return message except KeyError: - log.error('IGNORING MESSAGE: Invalid data_json received: {}'.format(data_json)) + log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) def write(self, data): self.terminado_server.pty.write(data['shellcmd']) diff --git a/lib/tfw/event_handler_base.py b/lib/tfw/event_handler_base.py index 09875b8..93172ce 100644 --- a/lib/tfw/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -39,10 +39,10 @@ class EventHandlerBase: if key != 'reset': return self.handle_event(key, message) else: return self.handle_reset(message) - def handle_event(self, key, data_json): + def handle_event(self, key, message): raise NotImplementedError - def handle_reset(self, data_json): + def handle_reset(self, message): return None def cleanup(self):