mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 03:41:55 +00:00
Make initialization of historymonitor the responsibility of client
This commit is contained in:
parent
c973b17141
commit
ba41c0b505
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user