mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 05:41:32 +00:00
Refactor connecting existing pipes to a method
This commit is contained in:
parent
d6f2eb987f
commit
aa1112af0e
@ -18,11 +18,7 @@ class PipeConnector:
|
||||
self.observer = self.build_observer(path)
|
||||
self.observer.on_any_event = self._on_any_event
|
||||
self.observer.start()
|
||||
for node in listdir(path):
|
||||
node_path = join(path, node)
|
||||
if self._is_pipe(node_path):
|
||||
self._create_pipe(node_path)
|
||||
LOG.debug('Connected to existing pipe "%s"', node_path)
|
||||
self._connect_existing_pipes(path)
|
||||
|
||||
def build_observer(self, path): # pylint: disable=no-self-use
|
||||
if not exists(path):
|
||||
@ -31,6 +27,13 @@ class PipeConnector:
|
||||
raise ValueError('Path does not exist or is not accessible.')
|
||||
return InotifyObserver(path, patterns=[f'*{self.reader_pattern}*', f'*{self.writer_pattern}*'])
|
||||
|
||||
def _connect_existing_pipes(self, path):
|
||||
for node in listdir(path):
|
||||
node_path = join(path, node)
|
||||
if self._is_pipe(node_path):
|
||||
self._create_pipe(node_path)
|
||||
LOG.debug('Connected to existing pipe "%s"', node_path)
|
||||
|
||||
def _on_any_event(self, event):
|
||||
path = event.src_path
|
||||
if self._is_pipe(path) and isinstance(event, InotifyFileCreatedEvent):
|
||||
|
Loading…
Reference in New Issue
Block a user