mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-26 07:51:32 +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.terminado_mini_server import TerminadoMiniServer
|
||||||
from tfw.components.history_monitor import BashMonitor
|
|
||||||
from tfw.event_handler_base import TriggerlessEventHandler
|
from tfw.event_handler_base import TriggerlessEventHandler
|
||||||
from tfw.config import TFWENV
|
from tfw.config import TFWENV
|
||||||
from tfw.config.logs import logging
|
from tfw.config.logs import logging
|
||||||
@ -8,13 +7,14 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class TerminadoEventHandler(TriggerlessEventHandler):
|
class TerminadoEventHandler(TriggerlessEventHandler):
|
||||||
def __init__(self, key):
|
def __init__(self, key, monitor):
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
self.working_directory = TFWENV.TERMINADO_DIR
|
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.terminado_server = TerminadoMiniServer('/terminal', TFWENV.TERMINADO_PORT, TFWENV.TERMINADO_WD, ['bash'])
|
||||||
self.commands = {'write': self.write,
|
self.commands = {'write': self.write,
|
||||||
'read': self.read}
|
'read': self.read}
|
||||||
|
if self._historymonitor:
|
||||||
self._historymonitor.watch()
|
self._historymonitor.watch()
|
||||||
self.terminado_server.listen()
|
self.terminado_server.listen()
|
||||||
|
|
||||||
@ -35,8 +35,10 @@ class TerminadoEventHandler(TriggerlessEventHandler):
|
|||||||
|
|
||||||
def read(self, data):
|
def read(self, data):
|
||||||
data['count'] = int(data.get('count', 1))
|
data['count'] = int(data.get('count', 1))
|
||||||
|
if self.historymonitor:
|
||||||
data['history'] = self.historymonitor.history[-data['count']:]
|
data['history'] = self.historymonitor.history[-data['count']:]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
|
if self.historymonitor:
|
||||||
self.historymonitor.stop()
|
self.historymonitor.stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user