2018-03-23 14:27:42 +00:00
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
|
2018-04-06 13:22:14 +00:00
|
|
|
from tfw.components import SourceCodeEventHandler, TerminadoEventHandler, ProcessManagingEventHandler, BashMonitor
|
2018-04-06 14:05:52 +00:00
|
|
|
from tfw.networking import MessageSender, ServerUplinkConnector
|
2018-03-25 14:34:31 +00:00
|
|
|
from tfw.config import TFWENV
|
2018-03-23 14:27:42 +00:00
|
|
|
from tfw.config.logs import logging
|
2018-03-31 22:45:15 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
2018-03-23 14:27:42 +00:00
|
|
|
|
|
|
|
|
2018-03-27 14:04:33 +00:00
|
|
|
def cenator(history):
|
2018-03-31 22:45:15 +00:00
|
|
|
LOG.debug('User executed command: "%s"', history[-1])
|
2018-03-27 14:04:33 +00:00
|
|
|
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]}})
|
2018-03-31 22:45:15 +00:00
|
|
|
except IndexError:
|
|
|
|
LOG.exception('Selectdir failed!')
|
2018-03-27 14:04:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
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}})
|
2018-03-31 22:45:15 +00:00
|
|
|
except IndexError:
|
|
|
|
LOG.exception('Togglenext failed!')
|
2018-03-27 14:04:33 +00:00
|
|
|
toggle_next.button_state = False
|
|
|
|
|
|
|
|
|
2018-03-23 14:27:42 +00:00
|
|
|
if __name__ == '__main__':
|
2018-03-31 22:45:15 +00:00
|
|
|
# pylint: disable=invalid-name
|
2018-04-06 13:22:14 +00:00
|
|
|
ide = SourceCodeEventHandler(key='webide', allowed_directories=[TFWENV.WEBIDE_WD],
|
|
|
|
directory=TFWENV.WEBIDE_WD, exclude=['*.pyc'])
|
2018-03-29 09:34:53 +00:00
|
|
|
terminado = TerminadoEventHandler(key='shell', monitor=BashMonitor(TFWENV.HISTFILE))
|
2018-03-27 14:04:33 +00:00
|
|
|
terminado.historymonitor.subscribe_callback(cenator)
|
|
|
|
terminado.historymonitor.subscribe_callback(selectdir)
|
|
|
|
terminado.historymonitor.subscribe_callback(toggle_next)
|
2018-03-23 14:27:42 +00:00
|
|
|
processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor)
|
|
|
|
|
|
|
|
eventhandlers = {ide, terminado, processmanager}
|
|
|
|
try:
|
|
|
|
IOLoop.instance().start()
|
|
|
|
finally:
|
2018-03-31 22:45:15 +00:00
|
|
|
for eh in eventhandlers:
|
|
|
|
eh.cleanup()
|