From ba41c0b505276e4695fab5682c4d70b5fd3feaef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 29 Mar 2018 11:34:08 +0200 Subject: [PATCH] Make initialization of historymonitor the responsibility of client --- lib/tfw/components/terminado_event_handler.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index 723bcfd..eb14431 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -1,5 +1,4 @@ from tfw.components.terminado_mini_server import TerminadoMiniServer -from tfw.components.history_monitor import BashMonitor from tfw.event_handler_base import TriggerlessEventHandler from tfw.config import TFWENV from tfw.config.logs import logging @@ -8,14 +7,15 @@ LOG = logging.getLogger(__name__) class TerminadoEventHandler(TriggerlessEventHandler): - def __init__(self, key): + def __init__(self, key, monitor): super().__init__(key) self.working_directory = TFWENV.TERMINADO_DIR - self._historymonitor = BashMonitor(TFWENV.HISTFILE) + self._historymonitor = monitor self.terminado_server = TerminadoMiniServer('/terminal', TFWENV.TERMINADO_PORT, TFWENV.TERMINADO_WD, ['bash']) self.commands = {'write': self.write, 'read': self.read} - self._historymonitor.watch() + if self._historymonitor: + self._historymonitor.watch() self.terminado_server.listen() @property @@ -35,8 +35,10 @@ class TerminadoEventHandler(TriggerlessEventHandler): def read(self, data): data['count'] = int(data.get('count', 1)) - data['history'] = self.historymonitor.history[-data['count']:] + if self.historymonitor: + data['history'] = self.historymonitor.history[-data['count']:] return data def cleanup(self): - self.historymonitor.stop() + if self.historymonitor: + self.historymonitor.stop()