Improve TFW lib layout

This commit is contained in:
Kristóf Tóth 2019-05-27 14:09:13 +02:00
parent 01d9003501
commit 2134d743c3
29 changed files with 54 additions and 48 deletions

View File

@ -5,7 +5,7 @@ from functools import wraps
from watchdog.events import FileSystemEventHandler as FileSystemWatchdogEventHandler
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector, Scope
from tfw.networking import ServerUplinkConnector, Scope
from tfw.decorators.rate_limiter import RateLimiter
from tfw.mixins.observer_mixin import ObserverMixin

View File

@ -3,7 +3,7 @@
from os.path import isdir, exists
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.mixins.monitor_manager_mixin import MonitorManagerMixin
from tfw.components.directory_monitor import DirectoryMonitor
from tfw.config.logs import logging

View File

@ -8,7 +8,7 @@ from datetime import datetime
from dateutil import parser as dateparser
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.components.snapshot_provider import SnapshotProvider
from tfw.config import TFWENV
from tfw.config.logs import logging

View File

@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
from contextlib import suppress
from tfw.networking.message_sender import MessageSender
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
class FrontendEventHandler(FrontendEventHandlerBase):

View File

@ -1,10 +1,10 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.crypto import KeyManager, sign_message, verify_message
from tfw.config.logs import logging
from tfw.networking.event_handlers.server_connector import Scope
from tfw.networking import Scope
LOG = logging.getLogger(__name__)

View File

@ -6,7 +6,7 @@ from glob import glob
from fnmatch import fnmatchcase
from typing import Iterable
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.mixins.monitor_manager_mixin import MonitorManagerMixin
from tfw.components.directory_monitor import DirectoryMonitor
from tfw.config.logs import logging

View File

@ -6,7 +6,7 @@ from os.path import dirname
from watchdog.events import PatternMatchingEventHandler as PatternMatchingWatchdogEventHandler
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector, Scope
from tfw.networking import ServerUplinkConnector, Scope
from tfw.decorators.rate_limiter import RateLimiter
from tfw.mixins.observer_mixin import ObserverMixin
from tfw.mixins.supervisor_mixin import SupervisorLogMixin

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.mixins.monitor_manager_mixin import MonitorManagerMixin
from tfw.components.log_monitor import LogMonitor
from tfw.config.logs import logging

View File

@ -9,7 +9,7 @@ from secrets import token_urlsafe
from threading import Thread
from contextlib import suppress
from tfw.event_handler_base import EventHandlerBase
from tfw.event_handlers import EventHandlerBase
from tfw.config.logs import logging
from .pipe_io_server import PipeIOServer, terminate_process_on_failure

View File

@ -3,7 +3,7 @@
from xmlrpc.client import Fault as SupervisorFault
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.mixins.supervisor_mixin import SupervisorMixin, SupervisorLogMixin
from tfw.components.directory_monitor import with_monitor_paused
from tfw.config.logs import logging

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from tfw.event_handler_base import FrontendEventHandlerBase
from tfw.event_handlers import FrontendEventHandlerBase
from tfw.components.terminado_mini_server import TerminadoMiniServer
from tfw.config import TFWENV
from tfw.config.logs import logging
@ -50,7 +50,6 @@ class TerminalEventHandler(FrontendEventHandlerBase):
return self._historymonitor
def handle_event(self, message):
LOG.debug('TerminadoEventHandler received event: %s', message)
try:
data = message['data']
message['data'] = self.commands[data['command']](data)

View File

@ -14,7 +14,7 @@ from cryptography.hazmat.primitives.hashes import SHA256
from cryptography.hazmat.primitives.hmac import HMAC as _HMAC
from cryptography.exceptions import InvalidSignature
from tfw.networking.serialization import message_bytes
from tfw.networking import message_bytes
from tfw.decorators.lazy_property import lazy_property
from tfw.config import TFWENV

View File

@ -1,6 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from .event_handler_base import EventHandlerBase, FrontendEventHandlerBase
from .event_handler_base import EventHandlerBase
from .frontend_event_handler_base import FrontendEventHandlerBase
from .boradcasting_event_handler import BroadcastingEventHandler
from .fsm_aware_event_handler import FSMAwareEventHandler

View File

@ -3,10 +3,11 @@
from abc import ABC
from tfw.event_handler_base.event_handler_base import EventHandlerBase
from tfw.networking.event_handlers.server_connector import Scope
from tfw.networking import Scope
from tfw.crypto import message_checksum
from .event_handler_base import EventHandlerBase
class BroadcastingEventHandler(EventHandlerBase, ABC):
# pylint: disable=abstract-method

View File

@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
from inspect import currentframe
from typing import Iterable
from tfw.networking.event_handlers.server_connector import ServerConnector, Scope
from tfw.networking import ServerConnector
from tfw.config.logs import logging
LOG = logging.getLogger(__name__)
@ -131,8 +131,3 @@ class EventHandlerBase(ABC):
instance for instance in locals_values
if isinstance(instance, cls)
}
class FrontendEventHandlerBase(EventHandlerBase): # pylint: disable=abstract-method
def send_message(self, message):
self.server_connector.send_message(message, Scope.WEBSOCKET)

View File

@ -0,0 +1,8 @@
from tfw.networking import Scope
from .event_handler_base import EventHandlerBase
class FrontendEventHandlerBase(EventHandlerBase): # pylint: disable=abstract-method
def send_message(self, message):
self.server_connector.send_message(message, Scope.WEBSOCKET)

View File

@ -2,7 +2,6 @@
# All Rights Reserved. See LICENSE file for details.
from tfw.crypto import KeyManager, verify_message
from tfw.config.logs import logging
LOG = logging.getLogger(__name__)

View File

@ -3,8 +3,8 @@
from abc import ABC
from tfw.event_handler_base.event_handler_base import EventHandlerBase
from tfw.networking.fsm_aware import FSMAware
from .event_handler_base import EventHandlerBase
from .fsm_aware import FSMAware
class FSMAwareEventHandler(EventHandlerBase, FSMAware, ABC):

View File

@ -1,6 +1,8 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from .serialization import serialize_tfw_msg, deserialize_tfw_msg, with_deserialize_tfw_msg, message_bytes
from .server_connector import ServerUplinkConnector, ServerDownlinkConnector, ServerConnector
from .event_handler_connector import EventHandlerConnector
from .message_sender import MessageSender
from .event_handlers.server_connector import ServerUplinkConnector as TFWServerConnector
from .server.tfw_server import TFWServer
from .scope import Scope

View File

@ -4,11 +4,12 @@
import zmq
from zmq.eventloop.zmqstream import ZMQStream
from tfw.networking.zmq_connector_base import ZMQConnectorBase
from tfw.networking.serialization import serialize_tfw_msg, with_deserialize_tfw_msg
from tfw.config import TFWENV
from tfw.config.logs import logging
from .serialization import serialize_tfw_msg, with_deserialize_tfw_msg
from .zmq_connector_base import ZMQConnectorBase
LOG = logging.getLogger(__name__)

View File

@ -1,2 +0,0 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from .server_connector import ServerUplinkConnector
class MessageSender:

View File

@ -0,0 +1,7 @@
from enum import Enum
class Scope(Enum):
ZMQ = 'zmq'
WEBSOCKET = 'websocket'
BROADCAST = 'broadcast'

View File

@ -1,2 +0,0 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.

View File

@ -2,16 +2,17 @@
# All Rights Reserved. See LICENSE file for details.
from functools import partial
from enum import Enum
import zmq
from zmq.eventloop.zmqstream import ZMQStream
from tfw.networking.zmq_connector_base import ZMQConnectorBase
from tfw.networking.serialization import serialize_tfw_msg, with_deserialize_tfw_msg
from tfw.config import TFWENV
from tfw.config.logs import logging
from .scope import Scope
from .serialization import serialize_tfw_msg, with_deserialize_tfw_msg
from .zmq_connector_base import ZMQConnectorBase
LOG = logging.getLogger(__name__)
@ -34,12 +35,6 @@ class ServerDownlinkConnector(ZMQConnectorBase):
self._zmq_sub_stream.close()
class Scope(Enum):
ZMQ = 'zmq'
WEBSOCKET = 'websocket'
BROADCAST = 'broadcast'
class ServerUplinkConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super(ServerUplinkConnector, self).__init__(zmq_context)

View File

@ -0,0 +1 @@
from .tfw_server import TFWServer

View File

@ -3,10 +3,11 @@
from tornado.web import Application
from tfw.networking.server.zmq_websocket_proxy import ZMQWebSocketProxy
from tfw.networking.server.event_handler_connector import EventHandlerConnector
from tfw.networking import EventHandlerConnector
from tfw.config.logs import logging
from .zmq_websocket_proxy import ZMQWebSocketProxy
LOG = logging.getLogger(__name__)

View File

@ -5,7 +5,7 @@ import json
from tornado.websocket import WebSocketHandler
from tfw.networking.event_handlers.server_connector import Scope
from tfw.networking import Scope
from tfw.config.logs import logging
LOG = logging.getLogger(__name__)

View File

@ -1,6 +1,6 @@
from tornado.ioloop import IOLoop
from tfw.networking import TFWServer
from tfw.server import TFWServer
from tfw.config import TFWENV