Move TriggerlessEventHandler logic to base class EventHandlerBase

This commit is contained in:
Kristóf Tóth 2018-04-18 18:47:51 +02:00
parent c909317ca0
commit 690f9bb190
6 changed files with 11 additions and 23 deletions

View File

@ -1,6 +1,6 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft. # Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details. # All Rights Reserved. See LICENSE file for details.
from .event_handler_base import TriggerlessEventHandler, TriggeredEventHandler from .event_handler_base import EventHandlerBase, TriggeredEventHandler
from .fsm_base import FSMBase from .fsm_base import FSMBase
from .linear_fsm import LinearFSM from .linear_fsm import LinearFSM

View File

@ -3,7 +3,7 @@
from os.path import isdir, exists from os.path import isdir, exists
from tfw import TriggerlessEventHandler from tfw import EventHandlerBase
from tfw.config.logs import logging from tfw.config.logs import logging
from tfw.mixins import MonitorManagerMixin from tfw.mixins import MonitorManagerMixin
from .directory_monitor import DirectoryMonitor from .directory_monitor import DirectoryMonitor
@ -11,7 +11,7 @@ from .directory_monitor import DirectoryMonitor
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class DirectoryMonitoringEventHandler(TriggerlessEventHandler, MonitorManagerMixin): class DirectoryMonitoringEventHandler(EventHandlerBase, MonitorManagerMixin):
def __init__(self, key, directory): def __init__(self, key, directory):
super().__init__(key) super().__init__(key)
self._directory = directory self._directory = directory

View File

@ -3,7 +3,7 @@
from xmlrpc.client import Fault as SupervisorFault from xmlrpc.client import Fault as SupervisorFault
from tfw import TriggerlessEventHandler from tfw import EventHandlerBase
from tfw.mixins import SupervisorMixin from tfw.mixins import SupervisorMixin
from tfw.config.logs import logging from tfw.config.logs import logging
from .directory_monitor import with_monitor_paused from .directory_monitor import with_monitor_paused
@ -22,7 +22,7 @@ class ProcessManager(SupervisorMixin):
return self.commands[command](process_name) return self.commands[command](process_name)
class ProcessManagingEventHandler(TriggerlessEventHandler): class ProcessManagingEventHandler(EventHandlerBase):
def __init__(self, key, dirmonitor=None): def __init__(self, key, dirmonitor=None):
super().__init__(key) super().__init__(key)
self.key = key self.key = key

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft. # Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details. # All Rights Reserved. See LICENSE file for details.
from tfw import TriggerlessEventHandler from tfw import EventHandlerBase
from tfw.config import TFWENV from tfw.config import TFWENV
from tfw.config.logs import logging from tfw.config.logs import logging
from tao.config import TAOENV from tao.config import TAOENV
@ -10,7 +10,7 @@ from .terminado_mini_server import TerminadoMiniServer
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class TerminadoEventHandler(TriggerlessEventHandler): class TerminadoEventHandler(EventHandlerBase):
def __init__(self, key, monitor): def __init__(self, key, monitor):
super().__init__(key) super().__init__(key)
self.working_directory = TFWENV.TERMINADO_DIR self.working_directory = TFWENV.TERMINADO_DIR

View File

@ -6,7 +6,7 @@ from glob import glob
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
from collections import Iterable from collections import Iterable
from tfw import TriggerlessEventHandler from tfw import EventHandlerBase
from tfw.mixins import MonitorManagerMixin from tfw.mixins import MonitorManagerMixin
from tfw.config.logs import logging from tfw.config.logs import logging
from .directory_monitor import DirectoryMonitor from .directory_monitor import DirectoryMonitor
@ -91,7 +91,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
return relpath(self._filepath(filename), start=self._workdir) return relpath(self._filepath(filename), start=self._workdir)
class WebideEventHandler(TriggerlessEventHandler, MonitorManagerMixin): class WebideEventHandler(EventHandlerBase, MonitorManagerMixin):
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
def __init__(self, key, directory, allowed_directories, selected_file=None, exclude=None): def __init__(self, key, directory, allowed_directories, selected_file=None, exclude=None):
super().__init__(key) super().__init__(key)

View File

@ -24,16 +24,10 @@ class EventHandlerBase(ABC):
return return
self.server_connector.send(response) self.server_connector.send(response)
@abstractmethod
def dispatch_handling(self, message): def dispatch_handling(self, message):
raise NotImplementedError
def _dispatch_handling(self, message):
# pylint: disable=no-else-return
if message['key'] != 'reset': if message['key'] != 'reset':
return self.handle_event(message) return self.handle_event(message)
else: return self.handle_reset(message)
return self.handle_reset(message)
@abstractmethod @abstractmethod
def handle_event(self, message): def handle_event(self, message):
@ -64,12 +58,6 @@ class EventHandlerBase(ABC):
self.subscriptions.clear() self.subscriptions.clear()
class TriggerlessEventHandler(EventHandlerBase, ABC):
# pylint: disable=abstract-method
def dispatch_handling(self, message):
return self._dispatch_handling(message)
class TriggeredEventHandler(EventHandlerBase, ABC): class TriggeredEventHandler(EventHandlerBase, ABC):
# pylint: disable=abstract-method # pylint: disable=abstract-method
def __init__(self, key, trigger): def __init__(self, key, trigger):
@ -78,5 +66,5 @@ class TriggeredEventHandler(EventHandlerBase, ABC):
def dispatch_handling(self, message): def dispatch_handling(self, message):
if message.get('trigger') == self.trigger: if message.get('trigger') == self.trigger:
return self._dispatch_handling(message) return super().dispatch_handling(message)
return None return None