mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 21:37:17 +00:00
56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
from tornado.ioloop import IOLoop
|
|
|
|
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.components.history_monitor import BashMonitor
|
|
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=['*.pyc'])
|
|
terminado = TerminadoEventHandler(key='shell', monitor=BashMonitor(TFWENV.HISTFILE))
|
|
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}
|
|
try:
|
|
IOLoop.instance().start()
|
|
finally:
|
|
for eh in eventhandlers: eh.cleanup()
|