1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-12 22:37:17 +00:00

Update event_handler_main to pre-baseimage split version

This commit is contained in:
Kristóf Tóth 2018-03-27 16:04:33 +02:00
parent 366567bacf
commit 557ccfc2db

View File

@ -4,14 +4,47 @@ from tfw.components.source_code_event_handler import SourceCodeEventHandler
from tfw.components.terminado_event_handler import TerminadoEventHandler
from tfw.components.process_managing_event_handler import ProcessManagingEventHandler
from tfw.config import TFWENV
from tfw.message_sender import MessageSender
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from tfw.config.logs import logging
log = logging.getLogger(__name__)
def cenator(history):
log.debug('User executed command: "{}"'.format(history[-1]))
MessageSender().send('JOHN CENA', 'You\'ve executed "{}"'.format(history[-1]))
def selectdir(history):
try:
cmd = history[-1].split()
if cmd[0] == 'selectdir':
ServerUplinkConnector().send_to_eventhandler('webide',
{'data': {'command': 'selectdir',
'directory': cmd[1]}})
except Exception:
log.exception('Selectdir failed!')
def toggle_next(history):
toggle_next.button_state = not toggle_next.button_state
try:
cmd = history[-1].split()
if cmd[0] == 'togglenext':
ServerUplinkConnector().send('messagecontrol',
{'data': {'command': 'showbutton',
'next_visibility': toggle_next.button_state}})
except Exception:
log.exception('Togglenext failed!')
toggle_next.button_state = False
if __name__ == '__main__':
ide = SourceCodeEventHandler(key='webide', directory=TFWENV.WEBIDE_WD, exclude=['__pycache__'])
ide = SourceCodeEventHandler(key='webide', directory=TFWENV.WEBIDE_WD, exclude=['*.pyc'])
terminado = TerminadoEventHandler(key='shell')
terminado.historymonitor.subscribe_callback(callback=lambda hist: log.debug('User executed command: "{}"'.format(hist[-1])))
terminado.historymonitor.subscribe_callback(cenator)
terminado.historymonitor.subscribe_callback(selectdir)
terminado.historymonitor.subscribe_callback(toggle_next)
processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor)
eventhandlers = {ide, terminado, processmanager}