Inject TFWENV dependencies to builtins

This commit is contained in:
Kristóf Tóth 2019-07-23 15:32:50 +02:00
parent ae69a094c7
commit c6e01d294d
6 changed files with 18 additions and 21 deletions

View File

@ -7,7 +7,6 @@ from datetime import datetime
from dateutil import parser as dateparser
from tfw.components.snapshot_provider import SnapshotProvider
from tfw.config import TFWENV
from tfw.networking import Scope
@ -17,7 +16,8 @@ LOG = logging.getLogger(__name__)
class DirectorySnapshottingEventHandler:
keys = ['snapshot']
def __init__(self, directories, exclude_unix_patterns=None):
def __init__(self, *, directories, snapshots_dir, exclude_unix_patterns=None):
self._snapshots_dir = snapshots_dir
self.snapshot_providers = {}
self._exclude_unix_patterns = exclude_unix_patterns
self.init_snapshot_providers(directories)
@ -37,10 +37,9 @@ class DirectorySnapshottingEventHandler:
self._exclude_unix_patterns
)
@staticmethod
def init_git_dir(index, directory):
def init_git_dir(self, index, directory):
git_dir = joinpath(
TFWENV.SNAPSHOTS_DIR,
self._snapshots_dir,
f'{basename(directory)}-{index}'
)
makedirs(git_dir, exist_ok=True)

View File

@ -24,7 +24,7 @@ class FSMManagingEventHandler:
An 'fsm_update' message is broadcasted after every successful
command.
"""
def __init__(self, fsm_type, require_signature=False):
def __init__(self, *, fsm_type, require_signature=False):
self.fsm = fsm_type()
self._fsm_updater = FSMUpdater(self.fsm)
self.auth_key = KeyManager().auth_key

View File

@ -47,7 +47,7 @@ class IdeEventHandler:
The API of each command is documented in their respective handler.
"""
def __init__(self, directory, allowed_directories, selected_file=None, exclude=None):
def __init__(self, *, directory, allowed_directories, selected_file=None, exclude=None):
"""
:param key: the key this instance should listen to
:param directory: working directory which the EventHandler should serve files from

View File

@ -1,6 +1,5 @@
import logging
from tfw.config import TFWENV
from tfw.components import LogInotifyObserver
@ -18,9 +17,10 @@ class LogMonitoringEventHandler:
The API of each command is documented in their respective handler.
"""
def __init__(self, process_name, log_tail=0):
def __init__(self, *, process_name, supervisor_uri, log_tail=0):
self.server_connector = None
self.process_name = process_name
self._supervisor_uri = supervisor_uri
self._initial_log_tail = log_tail
self._monitor = None
@ -32,7 +32,7 @@ class LogMonitoringEventHandler:
def start(self):
self._monitor = LogInotifyObserver(
server_connector=self.server_connector,
supervisor_uri=TFWENV.SUPERVISOR_HTTP_URI,
supervisor_uri=self._supervisor_uri,
process_name=self.process_name,
log_tail=self._initial_log_tail
)

View File

@ -1,7 +1,6 @@
import logging
from xmlrpc.client import Fault as SupervisorFault
from tfw.config import TFWENV
from tfw.networking import Scope
from tfw.components import ProcessManager, LogManager
@ -23,9 +22,9 @@ class ProcessManagingEventHandler(ProcessManager, LogManager):
Commands available: start, stop, restart, readlog
(the names are as self-documenting as it gets)
"""
def __init__(self, log_tail=0):
ProcessManager.__init__(self, TFWENV.SUPERVISOR_HTTP_URI)
LogManager.__init__(self, TFWENV.SUPERVISOR_HTTP_URI)
def __init__(self, *, supervisor_uri, log_tail=0):
ProcessManager.__init__(self, supervisor_uri)
LogManager.__init__(self, supervisor_uri)
self.log_tail = log_tail
self.commands = {
'start': self.start_process,

View File

@ -1,8 +1,6 @@
import logging
from tfw.components import BashMonitor, TerminadoMiniServer
from tfw.config import TFWENV
from tao.config import TAOENV
LOG = logging.getLogger(__name__)
@ -19,19 +17,20 @@ class TerminalEventHandler:
a command to be executed.
The API of each command is documented in their respective handler.
"""
def __init__(self):
def __init__(self, *, port, user, workind_directory, histfile):
"""
:param key: key this EventHandler listens to
:param monitor: tfw.components.HistoryMonitor instance to read command history from
"""
self.server_connector = None
self._histfile = histfile
self._historymonitor = None
bash_as_user_cmd = ['sudo', '-u', TAOENV.USER, 'bash']
bash_as_user_cmd = ['sudo', '-u', user, 'bash']
self.terminado_server = TerminadoMiniServer(
'/terminal',
TFWENV.TERMINADO_PORT,
TFWENV.TERMINADO_WD,
port,
workind_directory,
bash_as_user_cmd
)
@ -43,7 +42,7 @@ class TerminalEventHandler:
self.terminado_server.listen()
def start(self):
self._historymonitor = BashMonitor(self.server_connector, TFWENV.HISTFILE)
self._historymonitor = BashMonitor(self.server_connector, self._histfile)
self._historymonitor.start()
@property