Adjust the whole framework to event handler dependency inversion

This commit is contained in:
Kristóf Tóth
2019-07-12 23:25:16 +02:00
parent 42beafcf04
commit de78f48930
26 changed files with 169 additions and 254 deletions

View File

@ -1,6 +1,5 @@
from .commands_equal import CommandsEqual
from .file_manager import FileManager
from .fsm_aware import FSMAware
from .fsm_updater import FSMUpdater
from .history_monitor import BashMonitor, GDBMonitor
from .log_inotify_observer import LogInotifyObserver

View File

@ -1,42 +0,0 @@
import logging
from tfw.crypto import KeyManager, verify_message
LOG = logging.getLogger(__name__)
class FSMAware:
"""
Base class for stuff that has to be aware of the framework FSM.
This is done by processing 'fsm_update' messages.
"""
def __init__(self):
self.fsm_state = None
self.fsm_in_accepted_state = False
self.fsm_event_log = []
self._auth_key = KeyManager().auth_key
def refresh_on_fsm_update(self, message):
if message['key'] == 'fsm_update' and verify_message(self._auth_key, message):
self._handle_fsm_update(message)
return True
return False
def _handle_fsm_update(self, message):
try:
update_data = message['data']
new_state = update_data['current_state']
if self.fsm_state != new_state:
self.handle_fsm_step(**update_data)
self.fsm_state = new_state
self.fsm_in_accepted_state = update_data['in_accepted_state']
self.fsm_event_log.append(update_data)
except KeyError:
LOG.error('Invalid fsm_update message received!')
def handle_fsm_step(self, **kwargs):
"""
Called in case the TFW FSM has stepped.
:param kwargs: fsm_update 'data' field
"""

View File

@ -6,7 +6,7 @@ class FSMUpdater:
def fsm_update(self):
return {
'key': 'fsm_update',
'data': self.fsm_update_data
**self.fsm_update_data
}
@property

View File

@ -26,7 +26,7 @@ class TerminalCommands(ABC):
You can also use this class to create new commands similarly.
"""
def __init__(self, bashrc=None):
def __init__(self, bashrc):
self._command_method_regex = r'^command_(.+)$'
self.command_implemetations = self._build_command_to_implementation_dict()
if bashrc is not None: