1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 06:17:17 +00:00
test-tutorial-framework/solvable/src/event_handler_main.py

54 lines
2.2 KiB
Python
Raw Normal View History

from tornado.ioloop import IOLoop
2018-04-07 12:18:41 +00:00
from tfw.components import WebideEventHandler, TerminadoEventHandler, ProcessManagingEventHandler, BashMonitor
from tfw.components import TerminalCommands
from tfw.networking import MessageSender, TFWServerConnector
from tfw.config import TFWENV
from tfw.config.logs import logging
from tao.config import TAOENV
LOG = logging.getLogger(__name__)
def cenator(history):
LOG.debug('User executed command: "%s"', history[-1])
2018-04-19 07:19:32 +00:00
MessageSender().send('JOHN CENA', f'You\'ve executed "{history[-1]}"')
class TestCommands(TerminalCommands):
2018-04-18 18:45:17 +00:00
# pylint: disable=unused-argument, attribute-defined-outside-init, no-self-use
def command_selectdir(self, *args):
2018-04-12 13:12:50 +00:00
TFWServerConnector().send_to_eventhandler({'key': 'webide',
'data': {'command': 'selectdir',
'directory': args[0]}})
def command_trigger(self, *args):
2018-04-12 13:12:50 +00:00
TFWServerConnector().send({'key': '',
'trigger': args[0]})
def command_togglenext(self, *args):
if not hasattr(self, 'togglenext_visible'):
self.togglenext_visible = True
2018-04-12 13:12:50 +00:00
TFWServerConnector().send({'key': 'messagecontrol',
'data': {'command': 'showbutton',
'next_visibility': self.togglenext_visible}})
self.togglenext_visible = not self.togglenext_visible
if __name__ == '__main__':
# pylint: disable=invalid-name
2018-04-07 12:18:41 +00:00
ide = WebideEventHandler(key='webide', allowed_directories=[TFWENV.WEBIDE_WD],
directory=TFWENV.WEBIDE_WD, exclude=['*.pyc'])
terminado = TerminadoEventHandler(key='shell', monitor=BashMonitor(TFWENV.HISTFILE))
terminado.historymonitor.subscribe_callback(cenator)
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
terminado.historymonitor.subscribe_callback(commands.callback)
processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor)
eventhandlers = {ide, terminado, processmanager}
try:
IOLoop.instance().start()
finally:
for eh in eventhandlers:
eh.cleanup()