2018-03-23 14:27:42 +00:00
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
|
2018-04-26 08:12:47 +00:00
|
|
|
from tfw.components import IdeEventHandler, TerminalEventHandler, ProcessManagingEventHandler, BashMonitor
|
2018-04-12 08:55:33 +00:00
|
|
|
from tfw.components import TerminalCommands
|
2018-04-06 14:23:20 +00:00
|
|
|
from tfw.networking import MessageSender, TFWServerConnector
|
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-04-12 09:08:58 +00:00
|
|
|
from tao.config import TAOENV
|
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-04-19 07:19:32 +00:00
|
|
|
MessageSender().send('JOHN CENA', f'You\'ve executed "{history[-1]}"')
|
2018-03-27 14:04:33 +00:00
|
|
|
|
|
|
|
|
2018-04-12 08:55:33 +00:00
|
|
|
class TestCommands(TerminalCommands):
|
2018-04-18 18:45:17 +00:00
|
|
|
# pylint: disable=unused-argument, attribute-defined-outside-init, no-self-use
|
2018-04-12 08:37:47 +00:00
|
|
|
def command_selectdir(self, *args):
|
2018-04-20 15:33:28 +00:00
|
|
|
TFWServerConnector().send_to_eventhandler({'key': 'ide',
|
2018-04-12 13:12:50 +00:00
|
|
|
'data': {'command': 'selectdir',
|
2018-04-11 15:34:44 +00:00
|
|
|
'directory': args[0]}})
|
|
|
|
|
2018-04-12 08:37:47 +00:00
|
|
|
def command_trigger(self, *args):
|
2018-04-12 13:12:50 +00:00
|
|
|
TFWServerConnector().send({'key': '',
|
|
|
|
'trigger': args[0]})
|
2018-04-11 15:34:44 +00:00
|
|
|
|
2018-04-12 08:37:47 +00:00
|
|
|
def command_togglenext(self, *args):
|
2018-04-11 15:34:44 +00:00
|
|
|
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',
|
2018-04-11 15:34:44 +00:00
|
|
|
'next_visibility': self.togglenext_visible}})
|
|
|
|
self.togglenext_visible = not self.togglenext_visible
|
2018-03-27 14:04:33 +00:00
|
|
|
|
2018-04-19 14:23:46 +00:00
|
|
|
def command_seppuku_tfw(self, *args):
|
|
|
|
seppuku = ('nohup sh -c "supervisorctl restart tfwserver event_handler_main" &> /dev/null & '
|
|
|
|
'clear && echo "Committed seppuku! :)" && sleep infinity')
|
2018-04-20 12:51:08 +00:00
|
|
|
uplink = TFWServerConnector()
|
|
|
|
uplink.send_to_eventhandler({'key': 'shell',
|
|
|
|
'data': {'command': 'write',
|
|
|
|
'shellcmd': f'{seppuku}\n'}})
|
|
|
|
uplink.send({'key': 'dashboard',
|
|
|
|
'data' :{'command': 'reload_frontend'}})
|
2018-04-19 14:23:46 +00:00
|
|
|
|
2018-04-20 12:42:32 +00:00
|
|
|
def command_changelayout(self, *args):
|
|
|
|
message = {'key': 'dashboard',
|
|
|
|
'data': {'command': 'layout',
|
|
|
|
'layout': args[0]}}
|
|
|
|
if len(args) >= 2:
|
|
|
|
message['data']['hide_messages'] = (args[1] in ['yes', 'y', '1', 'true'])
|
|
|
|
TFWServerConnector().send(message)
|
|
|
|
|
2018-03-27 14:04:33 +00:00
|
|
|
|
2018-03-23 14:27:42 +00:00
|
|
|
if __name__ == '__main__':
|
2018-04-26 09:04:00 +00:00
|
|
|
ide = IdeEventHandler(key='ide', allowed_directories=[TFWENV.IDE_WD, TFWENV.WEBSERVICE_DIR],
|
2018-05-24 14:20:56 +00:00
|
|
|
directory=TFWENV.IDE_WD, exclude=['*.pyc'], additional_watched_directories=[TFWENV.WEBSERVICE_DIR])
|
2018-04-26 08:12:47 +00:00
|
|
|
terminado = TerminalEventHandler(key='shell', monitor=BashMonitor(TFWENV.HISTFILE))
|
2018-03-27 14:04:33 +00:00
|
|
|
terminado.historymonitor.subscribe_callback(cenator)
|
2018-04-12 09:08:58 +00:00
|
|
|
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
|
2018-04-11 15:34:44 +00:00
|
|
|
terminado.historymonitor.subscribe_callback(commands.callback)
|
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()
|