diff options
author | Sebastien Martini <seb@dbzteam.org> | 2014-07-06 14:39:48 +0200 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2014-07-06 14:39:48 +0200 |
commit | 8e190d29cc7f70a25e30b9b798e27a1c997fe7f5 (patch) | |
tree | 9d1f94586db66fc494801ee731bdd07b89cdc901 | |
parent | 499a975f651495c35f2616f829e946213a5454f9 (diff) | |
download | pyinotify-8e190d29cc7f70a25e30b9b798e27a1c997fe7f5.tar.gz |
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
-rwxr-xr-x | python2/pyinotify.py | 14 | ||||
-rwxr-xr-x | python3/pyinotify.py | 13 |
2 files changed, 27 insertions, 0 deletions
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: """ |