mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 08:01:57 +00:00
Implement custom TFW command demo
This commit is contained in:
parent
a5d0359ab8
commit
d4d6bdad0f
@ -5,6 +5,7 @@ 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__)
|
||||
|
||||
@ -14,10 +15,21 @@ def cenator(history):
|
||||
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__':
|
||||
ide = SourceCodeEventHandler(key='webide', directory=tfwenv.WEBIDE_WD, exclude=['__pycache__'])
|
||||
terminado = TerminadoEventHandler(key='shell')
|
||||
terminado.historymonitor.subscribe_callback(cenator)
|
||||
terminado.historymonitor.subscribe_callback(selectdir)
|
||||
processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor)
|
||||
|
||||
eventhandlers = {ide, terminado, processmanager}
|
||||
|
Loading…
Reference in New Issue
Block a user