87 lines
2.8 KiB
Python
87 lines
2.8 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
|
|
Logger([
|
|
Log(stderr, LogFormatter(20)),
|
|
Log(TFWENV.LOGFILE, VerboseLogFormatter())
|
|
]).start()
|
|
|
|
eh_factory = EventHandlerFactory()
|
|
# TFW builtin EventHandlers (required for their respective functionalities)
|
|
# TFW FSM
|
|
fsm_eh = eh_factory.build(FSMManagingEventHandler(
|
|
fsm_type=partial(
|
|
YamlFSM,
|
|
'test_fsm.yml',
|
|
{} # jinja2 variables, empty dict enables jinja2 without any variables
|
|
)
|
|
))
|
|
# Web IDE backend
|
|
ide_eh = eh_factory.build(IdeEventHandler(
|
|
allowed_directories=[TFWENV.IDE_WD, TFWENV.WEBSERVICE_DIR],
|
|
directory=TFWENV.IDE_WD,
|
|
exclude=['*.pyc']
|
|
))
|
|
# Web shell backend
|
|
terminal_eh = eh_factory.build(TerminalEventHandler())
|
|
# Handles 'deploy' button clicks
|
|
processmanager_eh = eh_factory.build(ProcessManagingEventHandler(
|
|
log_tail=2000
|
|
))
|
|
# Sends live logs of webservice process to frontend
|
|
logmonitor_eh = eh_factory.build(LogMonitoringEventHandler(
|
|
process_name='webservice',
|
|
log_tail=2000
|
|
))
|
|
# Manages filesystem snapshots of directories
|
|
snapshot_eh = eh_factory.build(DirectorySnapshottingEventHandler(
|
|
directories=[
|
|
TFWENV.IDE_WD,
|
|
TFWENV.WEBSERVICE_DIR
|
|
]
|
|
))
|
|
# Proxies frontend API calls to frontend
|
|
frontend_eh = eh_factory.build(FrontendEventHandler())
|
|
|
|
# Replace these with your custom event handlers
|
|
# Echoes executed commands to messages
|
|
cenator_eh = eh_factory.build(CenatorEventHandler())
|
|
# Echoes FSM steps
|
|
message_fsm_steps_eh = eh_factory.build(
|
|
MessageFSMStepsEventHandler(),
|
|
event_handler_type=FSMAwareEventHandler
|
|
)
|
|
# Catches special commands
|
|
commands_eh = eh_factory.build(TestCommandsEventHandler(
|
|
bashrc=f'/home/{TAOENV.USER}/.bashrc'
|
|
))
|
|
|
|
setup_signal_handlers()
|
|
IOLoop.instance().start()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|