Log PipeConnector events

This commit is contained in:
Kristóf Tóth 2019-08-30 17:45:54 +02:00
parent bb5c000b1d
commit a5db2f23a0
1 changed files with 9 additions and 4 deletions

View File

@ -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()