From aa1112af0eb28609d019c1780b1c88f45142fc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 11 Sep 2019 15:44:42 -0400 Subject: [PATCH] Refactor connecting existing pipes to a method --- .../pipe_io/pipe_connector/pipe_connector.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tfw/components/pipe_io/pipe_connector/pipe_connector.py b/tfw/components/pipe_io/pipe_connector/pipe_connector.py index fa423da..06ba4ab 100644 --- a/tfw/components/pipe_io/pipe_connector/pipe_connector.py +++ b/tfw/components/pipe_io/pipe_connector/pipe_connector.py @@ -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):