mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 16:17:17 +00:00
Create event handler to monitor bash commands
This commit is contained in:
parent
ba9d745e75
commit
9946114186
@ -19,13 +19,25 @@ LOG = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def cenator(history):
|
||||
class TerminalCallbackEventHandler(EventHandlerBase):
|
||||
"""
|
||||
Logs commands executed in terminal to messages.
|
||||
Logs commands executed in terminal to messages and invokes an
|
||||
additional callback function to handle special commands.
|
||||
!! Please remove from production code. !!
|
||||
"""
|
||||
LOG.debug('User executed command: "%s"', history[-1])
|
||||
MessageSender().send('JOHN CENA', f'You\'ve executed "{history[-1]}"')
|
||||
def __init__(self, key, callback):
|
||||
self.callback = callback
|
||||
super().__init__(key)
|
||||
|
||||
def handle_event(self, message):
|
||||
command = message['value']
|
||||
self.cenator(command)
|
||||
self.callback(command)
|
||||
|
||||
@staticmethod
|
||||
def cenator(command):
|
||||
LOG.debug('User executed command: "%s"', command)
|
||||
MessageSender().send('JOHN CENA', f'You\'ve executed "{command}"')
|
||||
|
||||
|
||||
class TestCommands(TerminalCommands):
|
||||
@ -123,6 +135,10 @@ def main():
|
||||
key='shell',
|
||||
monitor=BashMonitor(TFWENV.HISTFILE)
|
||||
)
|
||||
commands = TerminalCallbackEventHandler( # Reacts to terminal commands
|
||||
'history.bash',
|
||||
TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc').callback
|
||||
)
|
||||
processmanager = ProcessManagingEventHandler( # Handles 'deploy' button clicks
|
||||
key='processmanager',
|
||||
dirmonitor=ide.monitor,
|
||||
@ -147,11 +163,6 @@ def main():
|
||||
key='test'
|
||||
)
|
||||
|
||||
# Terminal command handlers
|
||||
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
|
||||
terminal.historymonitor.subscribe_callback(commands.callback)
|
||||
terminal.historymonitor.subscribe_callback(cenator)
|
||||
|
||||
event_handlers = EventHandlerBase.get_local_instances()
|
||||
def stop(sig, frame):
|
||||
for eh in event_handlers:
|
||||
|
Loading…
Reference in New Issue
Block a user