test-tutorial-framework/solvable/src/event_handler_main.py

95 lines
3.0 KiB
Python

import logging
from sys import stderr
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.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
LOG = logging.getLogger(__name__)
def main():
# 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
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
allowed_directories=[TFWENV.IDE_WD, TFWENV.WEBSERVICE_DIR],
directory=TFWENV.IDE_WD,
exclude=['*.pyc']
)
ide_eh = eh_factory.build(ide)
terminal = TerminalEventHandler() # Web shell backend
terminal_eh = eh_factory.build(terminal)
processmanager = ProcessManagingEventHandler( # Handles 'deploy' button clicks
log_tail=2000
)
processmanager_eh = eh_factory.build(processmanager)
logmonitor = LogMonitoringEventHandler( # Sends live logs of webservice process to frontend
process_name='webservice',
log_tail=2000
)
logmonitor_eh = eh_factory.build(logmonitor)
snapshot = DirectorySnapshottingEventHandler( # Manages filesystem snapshots of directories
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
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()
if __name__ == '__main__':
main()