1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-14 16:07:18 +00:00

Merge pull request #3 from avatao-content/terminalcommands

Terminalcommands
This commit is contained in:
Bokros Bálint 2018-04-12 11:20:25 +02:00 committed by GitHub
commit 01eaf08f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,11 @@
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
from tfw.components import WebideEventHandler, TerminadoEventHandler, ProcessManagingEventHandler, BashMonitor from tfw.components import WebideEventHandler, TerminadoEventHandler, ProcessManagingEventHandler, BashMonitor
from tfw.components import TerminalCommands
from tfw.networking import MessageSender, TFWServerConnector from tfw.networking import MessageSender, TFWServerConnector
from tfw.config import TFWENV from tfw.config import TFWENV
from tfw.config.logs import logging from tfw.config.logs import logging
from tao.config import TAOENV
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -13,28 +15,23 @@ def cenator(history):
MessageSender().send('JOHN CENA', 'You\'ve executed "{}"'.format(history[-1])) MessageSender().send('JOHN CENA', 'You\'ve executed "{}"'.format(history[-1]))
def selectdir(history): class TestCommands(TerminalCommands):
try: def command_selectdir(self, *args):
cmd = history[-1].split() TFWServerConnector().send_to_eventhandler('webide',
if cmd[0] == 'selectdir': {'data': {'command': 'selectdir',
TFWServerConnector().send_to_eventhandler('webide', 'directory': args[0]}})
{'data': {'command': 'selectdir',
'directory': cmd[1]}})
except IndexError:
LOG.exception('Selectdir failed!')
def command_trigger(self, *args):
TFWServerConnector().send('selectdir_needs_no_key',
{'trigger': args[0]})
def toggle_next(history): def command_togglenext(self, *args):
toggle_next.button_state = not toggle_next.button_state if not hasattr(self, 'togglenext_visible'):
try: self.togglenext_visible = True
cmd = history[-1].split() TFWServerConnector().send('messagecontrol',
if cmd[0] == 'togglenext': {'data': {'command': 'showbutton',
TFWServerConnector().send('messagecontrol', 'next_visibility': self.togglenext_visible}})
{'data': {'command': 'showbutton', self.togglenext_visible = not self.togglenext_visible
'next_visibility': toggle_next.button_state}})
except IndexError:
LOG.exception('Togglenext failed!')
toggle_next.button_state = False
if __name__ == '__main__': if __name__ == '__main__':
@ -43,8 +40,8 @@ if __name__ == '__main__':
directory=TFWENV.WEBIDE_WD, exclude=['*.pyc']) directory=TFWENV.WEBIDE_WD, exclude=['*.pyc'])
terminado = TerminadoEventHandler(key='shell', monitor=BashMonitor(TFWENV.HISTFILE)) terminado = TerminadoEventHandler(key='shell', monitor=BashMonitor(TFWENV.HISTFILE))
terminado.historymonitor.subscribe_callback(cenator) terminado.historymonitor.subscribe_callback(cenator)
terminado.historymonitor.subscribe_callback(selectdir) commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
terminado.historymonitor.subscribe_callback(toggle_next) terminado.historymonitor.subscribe_callback(commands.callback)
processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor) processmanager = ProcessManagingEventHandler(key='processmanager', dirmonitor=ide.monitor)
eventhandlers = {ide, terminado, processmanager} eventhandlers = {ide, terminado, processmanager}