From 8e190d29cc7f70a25e30b9b798e27a1c997fe7f5 Mon Sep 17 00:00:00 2001 From: Sebastien Martini Date: Sun, 6 Jul 2014 14:39:48 +0200 Subject: Add WatchManager attribute to ignore events. A new boolean attribute ignore_events (False by default) can be set to True in order to ignore reported events. Note that Watch descriptors are still valid and events are still received but there are ignored and not processed. Processing is resumed by re-assigning False to this attribute. Closes #44 --- python2/pyinotify.py | 14 ++++++++++++++ python3/pyinotify.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/python2/pyinotify.py b/python2/pyinotify.py index a91282f..4f07d65 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -1297,6 +1297,9 @@ class Notifier: """ while self._eventq: raw_event = self._eventq.popleft() # pop next event + if self._watch_manager.ignore_events: + log.debug("Event ignored: %s" % repr(raw_event)) + continue watch_ = self._watch_manager.get_watch(raw_event.wd) if (watch_ is None) and not (raw_event.mask & IN_Q_OVERFLOW): if not (raw_event.mask & IN_IGNORED): @@ -1752,6 +1755,7 @@ class WatchManager: filter for every call to add_watch. @type exclude_filter: callable object """ + self._ignore_events = False self._exclude_filter = exclude_filter self._wmd = {} # watch dict key: watch descriptor, value: watch @@ -2184,6 +2188,16 @@ class WatchManager: auto_add=False, do_glob=False, exclude_filter=lambda path: False) + def get_ignore_events(self): + return self._ignore_events + + def set_ignore_events(self, nval): + self._ignore_events = nval + + ignore_events = property(get_ignore_events, set_ignore_events, + "Make watch manager ignoring new events.") + + class RawOutputFormat: """ diff --git a/python3/pyinotify.py b/python3/pyinotify.py index 16d2d8c..67a7000 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1289,6 +1289,9 @@ class Notifier: """ while self._eventq: raw_event = self._eventq.popleft() # pop next event + if self._watch_manager.ignore_events: + log.debug("Event ignored: %s" % repr(raw_event)) + continue watch_ = self._watch_manager.get_watch(raw_event.wd) if (watch_ is None) and not (raw_event.mask & IN_Q_OVERFLOW): if not (raw_event.mask & IN_IGNORED): @@ -1737,6 +1740,7 @@ class WatchManager: filter for every call to add_watch. @type exclude_filter: callable object """ + self._ignore_events = False self._exclude_filter = exclude_filter self._wmd = {} # watch dict key: watch descriptor, value: watch @@ -2165,6 +2169,15 @@ class WatchManager: auto_add=False, do_glob=False, exclude_filter=lambda path: False) + def get_ignore_events(self): + return self._ignore_events + + def set_ignore_events(self, nval): + self._ignore_events = nval + + ignore_events = property(get_ignore_events, set_ignore_events, + "Make watch manager ignoring new events.") + class RawOutputFormat: """ -- cgit v1.2.1