mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:41:32 +00:00
Implement triggered and triggerless EventHandler base classes
This commit is contained in:
parent
fd1cb100ad
commit
940e74d6da
@ -2,7 +2,7 @@ from os.path import isfile, join, relpath
|
||||
from glob import glob
|
||||
|
||||
from tfw.components.mixins import SupervisorMixin
|
||||
from tfw.event_handler_base import EventHandlerBase
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.components.directory_monitor import DirectoryMonitor
|
||||
|
||||
from tfw.config.logs import logging
|
||||
@ -43,7 +43,7 @@ class FileManager:
|
||||
return relpath(self._filepath(filename), start=self._workdir)
|
||||
|
||||
|
||||
class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
class SourceCodeEventHandler(TriggerlessEventHandler, SupervisorMixin):
|
||||
def __init__(self, key, directory, process_name, selected_file=None):
|
||||
super().__init__(key)
|
||||
self.filemanager = FileManager(directory, selected_file=selected_file)
|
||||
|
@ -1,11 +1,11 @@
|
||||
from tfw.event_handler_base import EventHandlerBase
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.components.mixins import SupervisorMixin
|
||||
from tfw.config import tfwenv
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
class TerminadoEventHandler(TriggerlessEventHandler, SupervisorMixin):
|
||||
def __init__(self, key, process_name):
|
||||
super().__init__(key)
|
||||
self.working_directory = tfwenv.TERMINADO_DIR
|
||||
|
@ -28,10 +28,17 @@ class EventHandlerBase:
|
||||
from .message_sender import MessageSender
|
||||
ms = MessageSender()
|
||||
ms.send('JOHN CENA', next(self.cenerator))
|
||||
response = self.handle_event(key, message) if key != 'reset' else self.handle_reset(message)
|
||||
response = self.dispatch_handling(key, message)
|
||||
if response is None: return
|
||||
self.server_connector.send(key, response)
|
||||
|
||||
def dispatch_handling(self, key, message):
|
||||
raise NotImplementedError
|
||||
|
||||
def _dispatch_handling(self, key, message):
|
||||
if key != 'reset': return self.handle_event(key, message)
|
||||
else: return self.handle_reset(message)
|
||||
|
||||
def handle_event(self, key, data_json):
|
||||
raise NotImplementedError
|
||||
|
||||
@ -64,3 +71,18 @@ class EventHandlerBase:
|
||||
for sub in self.subscriptions:
|
||||
self.server_connector.unsubscribe(key=sub)
|
||||
self.subscriptions.clear()
|
||||
|
||||
|
||||
class TriggerlessEventHandler(EventHandlerBase):
|
||||
def dispatch_handling(self, key, message):
|
||||
return self._dispatch_handling(key, message)
|
||||
|
||||
|
||||
class TriggeredEventHandler(EventHandlerBase):
|
||||
def __init__(self, key, trigger):
|
||||
super().__init__(key)
|
||||
self.trigger = trigger
|
||||
|
||||
def dispatch_handling(self, key, message):
|
||||
if message.get('trigger') == self.trigger:
|
||||
return self._dispatch_handling(key, message)
|
||||
|
Loading…
Reference in New Issue
Block a user