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

Merge branch 'ocicat', the unrealized dream. Ocicat will return...

This commit is contained in:
Kristóf Tóth
2019-05-15 17:26:02 +02:00
13 changed files with 86 additions and 50 deletions

View File

@ -4,11 +4,12 @@ from signal import signal, SIGTERM, SIGINT
from tornado.ioloop import IOLoop
from tfw import YamlFSM, FSMAwareEventHandler, EventHandlerBase
from tfw.fsm import YamlFSM
from tfw.event_handler_base import EventHandlerBase, FSMAwareEventHandler
from tfw.components import IdeEventHandler, TerminalEventHandler
from tfw.components import ProcessManagingEventHandler, BashMonitor
from tfw.components import TerminalCommands, LogMonitoringEventHandler
from tfw.components import FSMManagingEventHandler
from tfw.components import FSMManagingEventHandler, DirectorySnapshottingEventHandler
from tfw.networking import MessageSender, TFWServerConnector
from tfw.config import TFWENV
from tfw.config.logs import logging
@ -87,22 +88,29 @@ class MessageFSMStepsEventHandler(FSMAwareEventHandler):
def handle_event(self, message):
pass
def handle_fsm_step(self, from_state, to_state, trigger):
def handle_fsm_step(self, **kwargs):
"""
When the FSM steps this method is invoked.
Receives a 'data' field from an fsm_update message as kwargs.
"""
MessageSender().send(
'FSM info',
f'FSM has stepped from state "{from_state}" '
f'to state "{to_state}" in response to trigger "{trigger}"'
f'FSM has stepped from state "{kwargs["last_event"]["from_state"]}" '
f'to state "{kwargs["current_state"]}" in response to trigger "{kwargs["last_event"]["trigger"]}"'
)
if __name__ == '__main__':
def main():
# pylint: disable=unused-variable
#
# TFW component EventHandlers (builtins, required for their respective functionalities)
fsm = FSMManagingEventHandler( # TFW FSM
fsm = FSMManagingEventHandler( # TFW FSM
key='fsm',
fsm_type=partial(YamlFSM, 'test_fsm.yml')
fsm_type=partial(
YamlFSM,
'test_fsm.yml',
{} # jinja2 variables, use empty dict to enable jinja2 parsing without any variables
)
)
ide = IdeEventHandler( # Web IDE backend
key='ide',
@ -124,17 +132,22 @@ if __name__ == '__main__':
process_name='webservice',
log_tail=2000
)
snapshot = DirectorySnapshottingEventHandler( # Manages filesystem snapshots of directories
key='snapshot',
directories=[
TFWENV.IDE_WD,
TFWENV.WEBSERVICE_DIR
]
)
# Your custom event handlers
message_fsm_steps = MessageFSMStepsEventHandler(
message_fsm_steps_eh = MessageFSMStepsEventHandler(
key='test'
)
# Terminal command handlers
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
terminal.historymonitor.subscribe_callback(commands.callback)
# Example terminal command callback
terminal.historymonitor.subscribe_callback(cenator)
event_handlers = EventHandlerBase.get_local_instances()
@ -146,3 +159,7 @@ if __name__ == '__main__':
signal(SIGINT, cleanup)
IOLoop.instance().start()
if __name__ == '__main__':
main()