From a5db2f23a003b1f5850734fdf33ad56c3943b6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 30 Aug 2019 17:45:54 +0200 Subject: [PATCH] Log PipeConnector events --- .../pipe_io/pipe_connector/pipe_connector.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tfw/components/pipe_io/pipe_connector/pipe_connector.py b/tfw/components/pipe_io/pipe_connector/pipe_connector.py index 820ff3f..04157ff 100644 --- a/tfw/components/pipe_io/pipe_connector/pipe_connector.py +++ b/tfw/components/pipe_io/pipe_connector/pipe_connector.py @@ -1,3 +1,4 @@ +import logging from stat import S_ISFIFO from os import access, mkdir, stat, R_OK from os.path import exists @@ -6,6 +7,8 @@ from pipe_io_server import PipeWriterServer from tfw.internals.inotify import InotifyObserver, InotifyFileCreatedEvent, InotifyFileDeletedEvent +LOG = logging.getLogger(__name__) + class PipeConnector: reader_pattern, writer_pattern = 'send', 'recv' @@ -27,15 +30,17 @@ class PipeConnector: path = event.src_path if self._is_pipe(path): if isinstance(event, InotifyFileCreatedEvent): - self._create_pipe(path) + self._on_create_pipe(path) + LOG.debug('Connected to new pipe "%s"', path) elif isinstance(event, InotifyFileDeletedEvent): - self._delete_pipe(path) + self._on_delete_pipe(path) + LOG.debug('Disconnected from deleted pipe "%s"', path) @staticmethod def _is_pipe(path): return exists(path) and S_ISFIFO(stat(path).st_mode) - def _create_pipe(self, path): + def _on_create_pipe(self, path): if self._find_pipe(path): return server = None @@ -61,7 +66,7 @@ class PipeConnector: def build_writer(self, path): # pylint: disable=no-self-use return PipeWriterServer(path, manage_pipes=False) - def _delete_pipe(self, path): + def _on_delete_pipe(self, path): pipes = self._find_pipe(path) if pipes: pipes[path].stop()