2019-06-10 13:35:09 +00:00
|
|
|
import logging
|
2019-06-28 15:36:03 +00:00
|
|
|
from sys import stderr
|
2018-06-29 20:08:05 +00:00
|
|
|
from functools import partial
|
2018-05-26 20:53:02 +00:00
|
|
|
|
2018-03-23 14:27:42 +00:00
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
|
2018-07-26 12:00:24 +00:00
|
|
|
from tfw.fsm import YamlFSM
|
2019-07-12 21:26:57 +00:00
|
|
|
from tfw.event_handlers import FSMAwareEventHandler
|
2019-07-24 13:52:38 +00:00
|
|
|
from tfw.components.ide import IdeHandler
|
|
|
|
from tfw.components.terminal import TerminalHandler
|
|
|
|
from tfw.components.frontend import FrontendHandler
|
|
|
|
from tfw.components.process_management import ProcessHandler, ProcessLogHandler
|
|
|
|
from tfw.components.snapshots import SnapshotHandler
|
|
|
|
from tfw.components.fsm import FSMHandler
|
2019-07-12 21:26:57 +00:00
|
|
|
from tfw.main import EventHandlerFactory, setup_signal_handlers
|
2019-06-28 15:36:03 +00:00
|
|
|
from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter
|
2019-07-24 13:52:38 +00:00
|
|
|
from tfw.config import TFWENV, TAOENV
|
2018-03-31 22:45:15 +00:00
|
|
|
|
2019-07-24 13:52:38 +00:00
|
|
|
from custom_handlers import CenatorHandler, TestCommandsHandler, messageFSMStepsHandler
|
2019-07-12 21:26:57 +00:00
|
|
|
|
2019-07-05 13:37:54 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2018-07-20 11:37:22 +00:00
|
|
|
|
|
|
|
|
2018-08-07 15:01:58 +00:00
|
|
|
def main():
|
2019-07-15 11:43:34 +00:00
|
|
|
# pylint: disable=unused-variable
|
2019-06-28 15:36:03 +00:00
|
|
|
Logger([
|
|
|
|
Log(stderr, LogFormatter(20)),
|
|
|
|
Log(TFWENV.LOGFILE, VerboseLogFormatter())
|
|
|
|
]).start()
|
2019-06-18 16:51:05 +00:00
|
|
|
|
2019-07-15 11:43:34 +00:00
|
|
|
eh_factory = EventHandlerFactory()
|
|
|
|
# TFW builtin EventHandlers (required for their respective functionalities)
|
|
|
|
# TFW FSM
|
2019-07-24 13:52:38 +00:00
|
|
|
fsm_eh = eh_factory.build(FSMHandler(
|
2018-07-27 11:59:14 +00:00
|
|
|
fsm_type=partial(
|
|
|
|
YamlFSM,
|
|
|
|
'test_fsm.yml',
|
2019-07-15 11:43:34 +00:00
|
|
|
{} # jinja2 variables, empty dict enables jinja2 without any variables
|
2018-07-27 11:59:14 +00:00
|
|
|
)
|
2019-07-15 11:43:34 +00:00
|
|
|
))
|
|
|
|
# Web IDE backend
|
2019-07-24 13:52:38 +00:00
|
|
|
ide_eh = eh_factory.build(IdeHandler(
|
2018-05-30 13:58:19 +00:00
|
|
|
allowed_directories=[TFWENV.IDE_WD, TFWENV.WEBSERVICE_DIR],
|
|
|
|
directory=TFWENV.IDE_WD,
|
2018-06-04 19:48:54 +00:00
|
|
|
exclude=['*.pyc']
|
2019-07-15 11:43:34 +00:00
|
|
|
))
|
|
|
|
# Web shell backend
|
2019-07-24 13:52:38 +00:00
|
|
|
terminal_eh = eh_factory.build(TerminalHandler(
|
|
|
|
port=TFWENV.TERMINADO_PORT,
|
|
|
|
user=TAOENV.USER,
|
|
|
|
workind_directory=TFWENV.TERMINADO_WD,
|
|
|
|
histfile=TFWENV.HISTFILE
|
|
|
|
))
|
2019-07-15 11:43:34 +00:00
|
|
|
# Handles 'deploy' button clicks
|
2019-07-24 13:52:38 +00:00
|
|
|
processmanager_eh = eh_factory.build(ProcessHandler(
|
|
|
|
supervisor_uri=TFWENV.SUPERVISOR_HTTP_URI,
|
|
|
|
log_tail=2000,
|
2019-07-15 11:43:34 +00:00
|
|
|
))
|
|
|
|
# Sends live logs of webservice process to frontend
|
2019-07-24 13:52:38 +00:00
|
|
|
logmonitor_eh = eh_factory.build(ProcessLogHandler(
|
2018-05-30 13:23:54 +00:00
|
|
|
process_name='webservice',
|
2019-07-24 13:52:38 +00:00
|
|
|
supervisor_uri=TFWENV.SUPERVISOR_HTTP_URI,
|
2018-05-30 11:15:13 +00:00
|
|
|
log_tail=2000
|
2019-07-15 11:43:34 +00:00
|
|
|
))
|
|
|
|
# Manages filesystem snapshots of directories
|
2019-07-24 13:52:38 +00:00
|
|
|
snapshot_eh = eh_factory.build(SnapshotHandler(
|
2018-08-07 15:03:41 +00:00
|
|
|
directories=[
|
|
|
|
TFWENV.IDE_WD,
|
|
|
|
TFWENV.WEBSERVICE_DIR
|
2019-07-24 13:52:38 +00:00
|
|
|
],
|
|
|
|
snapshots_dir=TFWENV.SNAPSHOTS_DIR
|
2019-07-15 11:43:34 +00:00
|
|
|
))
|
|
|
|
# Proxies frontend API calls to frontend
|
2019-07-24 13:52:38 +00:00
|
|
|
frontend_eh = eh_factory.build(FrontendHandler())
|
2019-07-15 11:43:34 +00:00
|
|
|
|
|
|
|
# Replace these with your custom event handlers
|
|
|
|
# Echoes executed commands to messages
|
2019-07-24 13:52:38 +00:00
|
|
|
cenator_eh = eh_factory.build(CenatorHandler())
|
2019-07-15 11:43:34 +00:00
|
|
|
# Echoes FSM steps
|
2019-07-12 21:26:57 +00:00
|
|
|
message_fsm_steps_eh = eh_factory.build(
|
2019-07-24 13:52:38 +00:00
|
|
|
messageFSMStepsHandler,
|
2019-07-12 21:26:57 +00:00
|
|
|
event_handler_type=FSMAwareEventHandler
|
|
|
|
)
|
2019-07-15 11:43:34 +00:00
|
|
|
# Catches special commands
|
2019-07-24 13:52:38 +00:00
|
|
|
commands_eh = eh_factory.build(TestCommandsHandler(
|
2019-07-12 21:26:57 +00:00
|
|
|
bashrc=f'/home/{TAOENV.USER}/.bashrc'
|
2019-07-15 11:43:34 +00:00
|
|
|
))
|
2018-07-20 11:37:22 +00:00
|
|
|
|
2019-07-08 09:42:03 +00:00
|
|
|
setup_signal_handlers()
|
2019-05-02 13:07:13 +00:00
|
|
|
IOLoop.instance().start()
|
2018-08-07 15:01:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|