Implement custom TFW command demo

This commit is contained in:
Kristóf Tóth 2018-03-14 14:12:09 +01:00
parent a5d0359ab8
commit d4d6bdad0f

View File

@ -5,6 +5,7 @@ from tfw.components.terminado_event_handler import TerminadoEventHandler
from tfw.components.process_managing_event_handler import ProcessManagingEventHandler from tfw.components.process_managing_event_handler import ProcessManagingEventHandler
from tfw.config import tfwenv from tfw.config import tfwenv
from tfw.message_sender import MessageSender from tfw.message_sender import MessageSender
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -14,10 +15,21 @@ def cenator(history):
MessageSender().send('JOHN CENA', 'You\'ve executed "{}"'.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!')
if __name__ == '__main__': if __name__ == '__main__':
ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['__pycache__']) ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['__pycache__'])
terminado = TerminadoEventHandler(key='shell') terminado = TerminadoEventHandler(key='shell')
terminado.historymonitor.subscribe_callback(cenator) terminado.historymonitor.subscribe_callback(cenator)
terminado.historymonitor.subscribe_callback(selectdir)
processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor) processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor)
eventhandlers = {ide, terminado, processmanager} eventhandlers = {ide, terminado, processmanager}