1. Bryan O'Sullivan
  2. python-inotify


Bryan O'Sullivan  committed 66198f3

AutoWatcher must add all directories recursively when a directory is created.

  • Participants
  • Parent commits 237239b
  • Branches default

Comments (0)

Files changed (2)

File inotify/__init__.py

View file
  • Ignore whitespace
 For a higher-level interface that remains highly efficient, use the
 inotify.watcher package.'''
+__author__ = "Bryan O'Sullivan <bos@serpentine.com>"
 from _inotify import *
 procfs_path = '/proc/sys/fs/inotify'

File inotify/watcher.py

View file
  • Ignore whitespace
 The AutoWatcher class is more useful, as it automatically watches
 newly-created directories on your behalf.'''
+__author__ = "Bryan O'Sullivan <bos@serpentine.com>"
 import _inotify as inotify
 import array
 import errno
     ignored_errors = [errno.ENOENT, errno.EPERM, errno.ENOTDIR]
-    def additer(self, path, mask, onerror=None):
+    def add_iter(self, path, mask, onerror=None):
         '''Add or modify watches over path and its subdirectories.
         Yield each added or modified watch descriptor.
         iterate over all of its results, even if you do not care what
         they are.  For example:
-            for wd in w.walk(path, mask):
+            for wd in w.add_iter(path, mask):
         By default, errors are ignored.  If optional arg "onerror" is
         submask = mask | inotify.IN_ONLYDIR
+        try:
+            yield self.add(path, mask)
+        except OSError, err:
+            if onerror and err.errno not in self.ignored_errors:
+                onerror(err)
         for root, dirs, names in os.walk(path, topdown=False, onerror=onerror):
             for d in dirs:
                 except OSError, err:
                     if onerror and err.errno not in self.ignored_errors:
-        yield self.add(path, mask)
+    def add_all(self, path, mask, onerror=None):
+        return [w for w in self.add_iter(path, mask, onerror)]
 class AutoWatcher(BasicWatcher):
     '''Watcher class that automatically watches newly created directories.'''
                     # See note about race avoidance via IN_ONLYDIR above.
                     mask = parentmask | inotify.IN_ONLYDIR
-                        self.add(evt.fullpath, mask)
+                        self.add_all(evt.fullpath, mask)
                     except OSError, err:
                         if err.errno not in self.ignored_errors: