diff options
Diffstat (limited to 'lib/pyinotify.py')
-rw-r--r-- | lib/pyinotify.py | 68 |
1 files changed, 16 insertions, 52 deletions
diff --git a/lib/pyinotify.py b/lib/pyinotify.py index 4eb03b092..3c5dab031 100644 --- a/lib/pyinotify.py +++ b/lib/pyinotify.py @@ -1,25 +1,9 @@ -#!/usr/bin/env python - +# # pyinotify.py - python interface to inotify # Copyright (c) 2005-2015 Sebastien Martini <seb@dbzteam.org> # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. +# SPDX-License-Identifier: MIT # -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. """ pyinotify @@ -68,7 +52,6 @@ from collections import deque from datetime import datetime, timedelta import time import re -import asyncore import glob import locale import subprocess @@ -612,14 +595,24 @@ class _ProcessEvent: @type event: Event object @return: By convention when used from the ProcessEvent class: - Returning False or None (default value) means keep on - executing next chained functors (see chain.py example). + executing next chained functors (see chain.py example). - Returning True instead means do not execute next processing functions. @rtype: bool @raise ProcessEventError: Event object undispatchable, unknown event. """ - stripped_mask = event.mask - (event.mask & IN_ISDIR) + stripped_mask = event.mask & ~IN_ISDIR + # Bitbake hack - we see event masks of 0x6, i.e., IN_MODIFY & IN_ATTRIB. + # The kernel inotify code can set more than one of the bits in the mask, + # fsnotify_change() in linux/fsnotify.h is quite clear that IN_ATTRIB, + # IN_MODIFY and IN_ACCESS can arrive together. + # This breaks the code below which assume only one mask bit is ever + # set in an event. We don't care about attrib or access in bitbake so + # drop those. + if stripped_mask & IN_MODIFY: + stripped_mask &= ~(IN_ATTRIB | IN_ACCESS) + maskname = EventsCodes.ALL_VALUES.get(stripped_mask) if maskname is None: raise ProcessEventError("Unknown mask 0x%08x" % stripped_mask) @@ -1290,7 +1283,7 @@ class Notifier: basename = os.path.basename(sys.argv[0]) or 'pyinotify' pid_file = os.path.join(dirname, basename + '.pid') - if pid_file != False and os.path.lexists(pid_file): + if pid_file and os.path.lexists(pid_file): err = 'Cannot daemonize: pid file %s already exists.' % pid_file raise NotifierError(err) @@ -1324,7 +1317,7 @@ class Notifier: fork_daemon() # Write pid - if pid_file != False: + if pid_file: flags = os.O_WRONLY|os.O_CREAT|os.O_NOFOLLOW|os.O_EXCL fd_pid = os.open(pid_file, flags, 0o0600) os.write(fd_pid, bytes(str(os.getpid()) + '\n', @@ -1491,35 +1484,6 @@ class ThreadedNotifier(threading.Thread, Notifier): self.loop() -class AsyncNotifier(asyncore.file_dispatcher, Notifier): - """ - This notifier inherits from asyncore.file_dispatcher in order to be able to - use pyinotify along with the asyncore framework. - - """ - def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, - threshold=0, timeout=None, channel_map=None): - """ - Initializes the async notifier. The only additional parameter is - 'channel_map' which is the optional asyncore private map. See - Notifier class for the meaning of the others parameters. - - """ - Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, - threshold, timeout) - asyncore.file_dispatcher.__init__(self, self._fd, channel_map) - - def handle_read(self): - """ - When asyncore tells us we can read from the fd, we proceed processing - events. This method can be overridden for handling a notification - differently. - - """ - self.read_events() - self.process_events() - - class TornadoAsyncNotifier(Notifier): """ Tornado ioloop adapter. |