mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-22 16:21:55 +00:00
Rework whole package structure (improved dependency handling)
This commit is contained in:
parent
c6e01d294d
commit
a23224aced
@ -1,7 +1,7 @@
|
||||
from collections import namedtuple
|
||||
from os import environ
|
||||
|
||||
from tfw.decorators.lazy_property import lazy_property
|
||||
from tfw.internals.lazy import lazy_property
|
||||
|
||||
|
||||
class LazyEnvironment:
|
||||
|
@ -1,10 +0,0 @@
|
||||
from .directory_snapshotting_event_handler import DirectorySnapshottingEventHandler
|
||||
from .frontend_event_handler import FrontendEventHandler
|
||||
from .fsm_managing_event_handler import FSMManagingEventHandler
|
||||
from .ide_event_handler import IdeEventHandler
|
||||
from .log_monitoring_event_handler import LogMonitoringEventHandler
|
||||
from .pipe_io_event_handler import PipeIOEventHandlerBase, PipeIOEventHandler
|
||||
from .pipe_io_event_handler import TransformerPipeIOEventHandler, CommandEventHandler
|
||||
from .process_managing_event_handler import ProcessManagingEventHandler
|
||||
from .terminal_commands_event_handler import TerminalCommandsEventHandler
|
||||
from .terminal_event_handler import TerminalEventHandler
|
@ -1,11 +0,0 @@
|
||||
from .commands_equal import CommandsEqual
|
||||
from .file_manager import FileManager
|
||||
from .fsm_updater import FSMUpdater
|
||||
from .history_monitor import BashMonitor, GDBMonitor
|
||||
from .log_inotify_observer import LogInotifyObserver
|
||||
from .message_sender import MessageSender
|
||||
from .message_storage import FrontendMessageStorage
|
||||
from .snapshot_provider import SnapshotProvider
|
||||
from .supervisor import ProcessManager, LogManager
|
||||
from .terminado_mini_server import TerminadoMiniServer
|
||||
from .terminal_commands import TerminalCommands
|
2
lib/tfw/components/frontend/__init__.py
Normal file
2
lib/tfw/components/frontend/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .frontend_handler import FrontendHandler
|
||||
from .message_sender import MessageSender
|
@ -1,8 +1,9 @@
|
||||
from tfw.networking import Scope
|
||||
from tfw.components import FrontendMessageStorage
|
||||
from tfw.internals.networking import Scope
|
||||
|
||||
from .message_storage import FrontendMessageStorage
|
||||
|
||||
|
||||
class FrontendEventHandler:
|
||||
class FrontendHandler:
|
||||
keys = ['message', 'queueMessages', 'dashboard', 'console']
|
||||
|
||||
def __init__(self):
|
1
lib/tfw/components/fsm/__init__.py
Normal file
1
lib/tfw/components/fsm/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .fsm_handler import FSMHandler
|
@ -1,14 +1,15 @@
|
||||
import logging
|
||||
|
||||
from tfw.crypto import KeyManager, sign_message, verify_message
|
||||
from tfw.networking import Scope
|
||||
from tfw.components import FSMUpdater
|
||||
from tfw.internals.crypto import KeyManager, sign_message, verify_message
|
||||
from tfw.internals.networking import Scope
|
||||
|
||||
from .fsm_updater import FSMUpdater
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FSMManagingEventHandler:
|
||||
class FSMHandler:
|
||||
keys = ['fsm']
|
||||
"""
|
||||
EventHandler responsible for managing the state machine of
|
1
lib/tfw/components/ide/__init__.py
Normal file
1
lib/tfw/components/ide/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .ide_handler import IdeHandler
|
@ -1,8 +1,9 @@
|
||||
import logging
|
||||
|
||||
from tfw.networking import Scope
|
||||
from tfw.components import FileManager
|
||||
from tfw.components.inotify import InotifyObserver
|
||||
from tfw.internals.networking import Scope
|
||||
from tfw.internals.inotify import InotifyObserver
|
||||
|
||||
from .file_manager import FileManager
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -31,7 +32,7 @@ BUILD_ARTIFACTS = (
|
||||
)
|
||||
|
||||
|
||||
class IdeEventHandler:
|
||||
class IdeHandler:
|
||||
keys = ['ide']
|
||||
# pylint: disable=too-many-arguments,anomalous-backslash-in-string
|
||||
"""
|
1
lib/tfw/components/pipe_io/__init__.py
Normal file
1
lib/tfw/components/pipe_io/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .pipe_io_handler import PipeIOHandler, PipeIOHandlerBase, TransformerPipeIOHandler, CommandHandler
|
@ -10,14 +10,14 @@ from secrets import token_urlsafe
|
||||
from threading import Thread
|
||||
from contextlib import suppress
|
||||
|
||||
from tfw.components.pipe_io_server import PipeIOServer, terminate_process_on_failure
|
||||
from .pipe_io_server import PipeIOServer, terminate_process_on_failure
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
DEFAULT_PERMISSIONS = 0o600
|
||||
|
||||
|
||||
class PipeIOEventHandlerBase:
|
||||
class PipeIOHandlerBase:
|
||||
keys = ['']
|
||||
|
||||
def __init__(self, in_pipe_path, out_pipe_path, permissions=DEFAULT_PERMISSIONS):
|
||||
@ -50,7 +50,7 @@ class CallbackPipeIOServer(PipeIOServer):
|
||||
LOG.exception('Failed to handle message %s from pipe %s!', message, self.in_pipe)
|
||||
|
||||
|
||||
class PipeIOEventHandler(PipeIOEventHandlerBase):
|
||||
class PipeIOHandler(PipeIOHandlerBase):
|
||||
def handle_event(self, message, _):
|
||||
json_bytes = dumps(message).encode()
|
||||
self.pipe_io.send_message(json_bytes)
|
||||
@ -60,7 +60,7 @@ class PipeIOEventHandler(PipeIOEventHandlerBase):
|
||||
self.server_connector.send_message(json)
|
||||
|
||||
|
||||
class TransformerPipeIOEventHandler(PipeIOEventHandlerBase):
|
||||
class TransformerPipeIOHandler(PipeIOHandlerBase):
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(
|
||||
self, in_pipe_path, out_pipe_path,
|
||||
@ -97,7 +97,7 @@ class TransformerPipeIOEventHandler(PipeIOEventHandlerBase):
|
||||
self.server_connector.send_message(json_message)
|
||||
|
||||
|
||||
class CommandEventHandler(PipeIOEventHandler):
|
||||
class CommandHandler(PipeIOHandler):
|
||||
def __init__(self, command, permissions=DEFAULT_PERMISSIONS):
|
||||
super().__init__(
|
||||
self._generate_tempfilename(),
|
2
lib/tfw/components/process_management/__init__.py
Normal file
2
lib/tfw/components/process_management/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .process_handler import ProcessHandler
|
||||
from .process_log_handler import ProcessLogHandler
|
@ -1,19 +1,19 @@
|
||||
import logging
|
||||
|
||||
from tfw.networking import Scope
|
||||
from tfw.internals.networking import Scope
|
||||
from tfw.internals.inotify import InotifyObserver
|
||||
|
||||
from .inotify import InotifyObserver
|
||||
from .supervisor import LogManager
|
||||
from .supervisor import ProcessLogManager
|
||||
|
||||
|
||||
class LogInotifyObserver(InotifyObserver, LogManager):
|
||||
class LogInotifyObserver(InotifyObserver, ProcessLogManager):
|
||||
def __init__(self, server_connector, supervisor_uri, process_name, log_tail=0):
|
||||
self._prevent_log_recursion()
|
||||
self._server_connector = server_connector
|
||||
self._process_name = process_name
|
||||
self.log_tail = log_tail
|
||||
self._procinfo = None
|
||||
LogManager.__init__(self, supervisor_uri)
|
||||
ProcessLogManager.__init__(self, supervisor_uri)
|
||||
InotifyObserver.__init__(self, self._get_logfiles())
|
||||
|
||||
@staticmethod
|
@ -1,14 +1,15 @@
|
||||
import logging
|
||||
from xmlrpc.client import Fault as SupervisorFault
|
||||
|
||||
from tfw.networking import Scope
|
||||
from tfw.components import ProcessManager, LogManager
|
||||
from tfw.internals.networking import Scope
|
||||
|
||||
from .supervisor import ProcessManager, ProcessLogManager
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProcessManagingEventHandler(ProcessManager, LogManager):
|
||||
class ProcessHandler(ProcessManager, ProcessLogManager):
|
||||
keys = ['processmanager']
|
||||
"""
|
||||
Event handler that can manage processes managed by supervisor.
|
||||
@ -24,7 +25,7 @@ class ProcessManagingEventHandler(ProcessManager, LogManager):
|
||||
"""
|
||||
def __init__(self, *, supervisor_uri, log_tail=0):
|
||||
ProcessManager.__init__(self, supervisor_uri)
|
||||
LogManager.__init__(self, supervisor_uri)
|
||||
ProcessLogManager.__init__(self, supervisor_uri)
|
||||
self.log_tail = log_tail
|
||||
self.commands = {
|
||||
'start': self.start_process,
|
@ -1,12 +1,12 @@
|
||||
import logging
|
||||
|
||||
from tfw.components import LogInotifyObserver
|
||||
from .log_inotify_observer import LogInotifyObserver
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LogMonitoringEventHandler:
|
||||
class ProcessLogHandler:
|
||||
keys = ['logmonitor']
|
||||
"""
|
||||
Monitors the output of a supervisor process (stdout, stderr) and
|
@ -22,7 +22,7 @@ class ProcessManager(SupervisorBase):
|
||||
self.start_process(process_name)
|
||||
|
||||
|
||||
class LogManager(SupervisorBase):
|
||||
class ProcessLogManager(SupervisorBase):
|
||||
def read_stdout(self, process_name, tail=0):
|
||||
return self.supervisor.readProcessStdoutLog(process_name, -tail, 0)
|
||||
|
1
lib/tfw/components/snapshots/__init__.py
Normal file
1
lib/tfw/components/snapshots/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .snapshot_handler import SnapshotHandler
|
@ -6,14 +6,15 @@ from datetime import datetime
|
||||
|
||||
from dateutil import parser as dateparser
|
||||
|
||||
from tfw.components.snapshot_provider import SnapshotProvider
|
||||
from tfw.networking import Scope
|
||||
from tfw.internals.networking import Scope
|
||||
|
||||
from .snapshot_provider import SnapshotProvider
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DirectorySnapshottingEventHandler:
|
||||
class SnapshotHandler:
|
||||
keys = ['snapshot']
|
||||
|
||||
def __init__(self, *, directories, snapshots_dir, exclude_unix_patterns=None):
|
3
lib/tfw/components/terminal/__init__.py
Normal file
3
lib/tfw/components/terminal/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .terminal_handler import TerminalHandler
|
||||
from .terminal_commands_handler import TerminalCommandsHandler
|
||||
from .commands_equal import CommandsEqual
|
@ -1,7 +1,7 @@
|
||||
from shlex import split
|
||||
from re import search
|
||||
|
||||
from tfw.decorators.lazy_property import lazy_property
|
||||
from tfw.internals.lazy import lazy_property
|
||||
|
||||
|
||||
class CommandsEqual:
|
@ -2,7 +2,7 @@ from re import findall
|
||||
from re import compile as compileregex
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from tfw.components.inotify import InotifyObserver
|
||||
from tfw.internals.inotify import InotifyObserver
|
||||
|
||||
|
||||
class HistoryMonitor(ABC, InotifyObserver):
|
@ -1,7 +1,7 @@
|
||||
from tfw.components import TerminalCommands
|
||||
from .terminal_commands import TerminalCommands
|
||||
|
||||
|
||||
class TerminalCommandsEventHandler(TerminalCommands):
|
||||
class TerminalCommandsHandler(TerminalCommands):
|
||||
keys = ['history.bash']
|
||||
|
||||
def handle_event(self, message, _):
|
@ -1,12 +1,13 @@
|
||||
import logging
|
||||
|
||||
from tfw.components import BashMonitor, TerminadoMiniServer
|
||||
from .history_monitor import BashMonitor
|
||||
from .terminado_mini_server import TerminadoMiniServer
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TerminalEventHandler:
|
||||
class TerminalHandler:
|
||||
keys = ['shell']
|
||||
"""
|
||||
Event handler responsible for managing terminal sessions for frontend xterm
|
2
lib/tfw/event_handlers.py
Normal file
2
lib/tfw/event_handlers.py
Normal file
@ -0,0 +1,2 @@
|
||||
# pylint: disable=unused-import
|
||||
from tfw.internals.event_handling import EventHandler, FSMAwareEventHandler
|
@ -4,7 +4,7 @@ from datetime import datetime
|
||||
|
||||
from transitions import Machine, MachineError
|
||||
|
||||
from tfw.mixins.callback_mixin import CallbackMixin
|
||||
from tfw.internals.callback_mixin import CallbackMixin
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from transitions import State
|
||||
|
||||
from tfw.fsm.fsm_base import FSMBase
|
||||
from .fsm_base import FSMBase
|
||||
|
||||
|
||||
class LinearFSM(FSMBase):
|
||||
|
@ -6,7 +6,7 @@ import yaml
|
||||
import jinja2
|
||||
from transitions import State
|
||||
|
||||
from tfw.fsm.fsm_base import FSMBase
|
||||
from .fsm_base import FSMBase
|
||||
|
||||
|
||||
class YamlFSM(FSMBase):
|
||||
|
@ -1,6 +1,6 @@
|
||||
from functools import partial
|
||||
|
||||
from tfw.decorators.lazy_property import lazy_property
|
||||
from .lazy import lazy_property
|
||||
|
||||
|
||||
class CallbackMixin:
|
@ -11,8 +11,8 @@ from cryptography.hazmat.primitives.hashes import SHA256
|
||||
from cryptography.hazmat.primitives.hmac import HMAC as _HMAC
|
||||
from cryptography.exceptions import InvalidSignature
|
||||
|
||||
from tfw.networking import message_bytes
|
||||
from tfw.decorators.lazy_property import lazy_property
|
||||
from tfw.internals.networking import message_bytes
|
||||
from tfw.internals.lazy import lazy_property
|
||||
from tfw.config import TFWENV
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import logging
|
||||
|
||||
from tfw.crypto import KeyManager, verify_message
|
||||
from tfw.internals.crypto import KeyManager, verify_message
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
1
lib/tfw/internals/server/__init__.py
Normal file
1
lib/tfw/internals/server/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .zmq_websocket_router import ZMQWebSocketRouter
|
@ -3,7 +3,7 @@ import logging
|
||||
|
||||
from tornado.websocket import WebSocketHandler
|
||||
|
||||
from tfw.networking import Scope
|
||||
from tfw.internals.networking import Scope
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -102,7 +102,7 @@ class LogFormatter(Formatter):
|
||||
|
||||
|
||||
class VerboseLogFormatter(Formatter):
|
||||
def format(self, record):
|
||||
def format(self, record): # pylint: disable=no-self-use
|
||||
date = datetime.utcfromtimestamp(record.created).strftime('%H:%M:%S')
|
||||
if record.args:
|
||||
message = record.msg % record.args
|
||||
|
@ -1,3 +1,4 @@
|
||||
from .tfw_connector import TFWUplinkConnector, TFWConnector
|
||||
from .event_handler_factory import EventHandlerFactory
|
||||
from .signal_handling import setup_signal_handlers
|
||||
from .tfw_server import TFWServer
|
||||
|
@ -1,4 +1,4 @@
|
||||
from tfw.event_handlers import EventHandlerFactoryBase
|
||||
from tfw.internals.event_handling import EventHandlerFactoryBase
|
||||
|
||||
from .tfw_connector import TFWConnector
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from signal import signal, SIGTERM, SIGINT
|
||||
|
||||
from tfw.event_handlers import EventHandler
|
||||
from tfw.internals.event_handling import EventHandler
|
||||
|
||||
|
||||
def setup_signal_handlers():
|
||||
|
@ -1,4 +1,4 @@
|
||||
from tfw.networking import ServerConnector, ServerUplinkConnector
|
||||
from tfw.internals.networking import ServerConnector, ServerUplinkConnector
|
||||
from tfw.config import TFWENV
|
||||
|
||||
|
||||
|
@ -2,10 +2,10 @@ import logging
|
||||
|
||||
from tornado.web import Application
|
||||
|
||||
from tfw.networking import EventHandlerConnector
|
||||
from tfw.internals.networking import EventHandlerConnector
|
||||
from tfw.internals.server import ZMQWebSocketRouter
|
||||
from tfw.config import TFWENV
|
||||
|
||||
from .zmq_websocket_router import ZMQWebSocketRouter
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -1 +0,0 @@
|
||||
from .tfw_server import TFWServer
|
@ -2,7 +2,7 @@ from sys import stderr
|
||||
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from tfw.server import TFWServer
|
||||
from tfw.main import TFWServer
|
||||
from tfw.config import TFWENV
|
||||
from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user