1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-12 19:37:16 +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 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__)
@ -13,28 +15,23 @@ def cenator(history):
MessageSender().send('JOHN CENA', 'You\'ve executed "{}"'.format(history[-1]))
def selectdir(history):
try:
cmd = history[-1].split()
if cmd[0] == 'selectdir':
TFWServerConnector().send_to_eventhandler('webide',
{'data': {'command': 'selectdir',
'directory': cmd[1]}})
except IndexError:
LOG.exception('Selectdir failed!')
class TestCommands(TerminalCommands):
def command_selectdir(self, *args):
TFWServerConnector().send_to_eventhandler('webide',
{'data': {'command': 'selectdir',
'directory': args[0]}})
def command_trigger(self, *args):
TFWServerConnector().send('selectdir_needs_no_key',
{'trigger': args[0]})
def toggle_next(history):
toggle_next.button_state = not toggle_next.button_state
try:
cmd = history[-1].split()
if cmd[0] == 'togglenext':
TFWServerConnector().send('messagecontrol',
{'data': {'command': 'showbutton',
'next_visibility': toggle_next.button_state}})
except IndexError:
LOG.exception('Togglenext failed!')
toggle_next.button_state = False
def command_togglenext(self, *args):
if not hasattr(self, 'togglenext_visible'):
self.togglenext_visible = True
TFWServerConnector().send('messagecontrol',
{'data': {'command': 'showbutton',
'next_visibility': self.togglenext_visible}})
self.togglenext_visible = not self.togglenext_visible
if __name__ == '__main__':
@ -43,8 +40,8 @@ if __name__ == '__main__':
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)
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}