Make initialization of historymonitor the responsibility of client

This commit is contained in:
Kristóf Tóth 2018-03-29 11:34:08 +02:00
parent c973b17141
commit ba41c0b505

View File

@ -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,13 +7,14 @@ 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}
if self._historymonitor:
self._historymonitor.watch()
self.terminado_server.listen()
@ -35,8 +35,10 @@ class TerminadoEventHandler(TriggerlessEventHandler):
def read(self, data):
data['count'] = int(data.get('count', 1))
if self.historymonitor:
data['history'] = self.historymonitor.history[-data['count']:]
return data
def cleanup(self):
if self.historymonitor:
self.historymonitor.stop()