mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2025-07-14 01:46:23 +00:00
Use new event handling model
This commit is contained in:
@ -5,73 +5,87 @@ from functools import partial
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from tfw.fsm import YamlFSM
|
||||
from tfw.event_handlers import FSMAwareEventHandler
|
||||
from tfw.builtins import IdeEventHandler, TerminalEventHandler, FrontendEventHandler
|
||||
from tfw.builtins import LogMonitoringEventHandler, ProcessManagingEventHandler
|
||||
from tfw.builtins import DirectorySnapshottingEventHandler, FSMManagingEventHandler
|
||||
from tfw.config import TFWENV
|
||||
from tfw.main import EventHandlerFactory, setup_signal_handlers
|
||||
from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter
|
||||
from tfw.config import TFWENV
|
||||
from tao.config import TAOENV
|
||||
|
||||
from custom_event_handlers import MessageFSMStepsEventHandler
|
||||
from custom_event_handlers import CenatorEventHandler, TestCommandsEventHandler
|
||||
from signal_handling import setup_signal_handlers
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
# pylint: disable=unused-variable
|
||||
# pylint: disable=unused-variable,too-many-locals
|
||||
Logger([
|
||||
Log(stderr, LogFormatter(20)),
|
||||
Log(TFWENV.LOGFILE, VerboseLogFormatter())
|
||||
]).start()
|
||||
eh_factory = EventHandlerFactory()
|
||||
|
||||
# TFW component EventHandlers (builtins, required for their respective functionalities)
|
||||
fsm = FSMManagingEventHandler( # TFW FSM
|
||||
key='fsm',
|
||||
fsm_type=partial(
|
||||
YamlFSM,
|
||||
'test_fsm.yml',
|
||||
{} # jinja2 variables, use empty dict to enable jinja2 parsing without any variables
|
||||
)
|
||||
)
|
||||
fsm_eh = eh_factory.build(fsm)
|
||||
|
||||
ide = IdeEventHandler( # Web IDE backend
|
||||
key='ide',
|
||||
allowed_directories=[TFWENV.IDE_WD, TFWENV.WEBSERVICE_DIR],
|
||||
directory=TFWENV.IDE_WD,
|
||||
exclude=['*.pyc']
|
||||
)
|
||||
terminal = TerminalEventHandler( # Web shell backend
|
||||
key='shell'
|
||||
)
|
||||
cenator = CenatorEventHandler('history.bash') # Reacts to terminal commands
|
||||
commands = TestCommandsEventHandler( # Catches special commands
|
||||
key='history.bash',
|
||||
bashrc=f'/home/{TAOENV.USER}/.bashrc'
|
||||
)
|
||||
ide_eh = eh_factory.build(ide)
|
||||
|
||||
terminal = TerminalEventHandler() # Web shell backend
|
||||
terminal_eh = eh_factory.build(terminal)
|
||||
|
||||
processmanager = ProcessManagingEventHandler( # Handles 'deploy' button clicks
|
||||
key='processmanager',
|
||||
log_tail=2000
|
||||
)
|
||||
processmanager_eh = eh_factory.build(processmanager)
|
||||
|
||||
logmonitor = LogMonitoringEventHandler( # Sends live logs of webservice process to frontend
|
||||
key='logmonitor',
|
||||
process_name='webservice',
|
||||
log_tail=2000
|
||||
)
|
||||
logmonitor_eh = eh_factory.build(logmonitor)
|
||||
|
||||
snapshot = DirectorySnapshottingEventHandler( # Manages filesystem snapshots of directories
|
||||
key='snapshot',
|
||||
directories=[
|
||||
TFWENV.IDE_WD,
|
||||
TFWENV.WEBSERVICE_DIR
|
||||
]
|
||||
)
|
||||
snapshot_eh = eh_factory.build(snapshot)
|
||||
|
||||
frontend = FrontendEventHandler() # Proxies frontend API calls to frontend
|
||||
frontend_eh = eh_factory.build(frontend)
|
||||
|
||||
# Your custom event handlers
|
||||
message_fsm_steps_eh = MessageFSMStepsEventHandler(
|
||||
key='test'
|
||||
cenator = CenatorEventHandler()
|
||||
cenator_eh = eh_factory.build(cenator)
|
||||
|
||||
message_fsm_steps = MessageFSMStepsEventHandler()
|
||||
message_fsm_steps_eh = eh_factory.build(
|
||||
message_fsm_steps,
|
||||
event_handler_type=FSMAwareEventHandler
|
||||
)
|
||||
|
||||
commands = TestCommandsEventHandler( # Catches special commands
|
||||
bashrc=f'/home/{TAOENV.USER}/.bashrc'
|
||||
)
|
||||
commands_eh = eh_factory.build(commands)
|
||||
|
||||
setup_signal_handlers()
|
||||
IOLoop.instance().start()
|
||||
|
||||
|
Reference in New Issue
Block a user