diff options
author | Sebastien Martini <seb@dbzteam.org> | 2009-02-23 14:22:16 +0100 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2009-02-23 14:22:16 +0100 |
commit | 5070c603a73ab911703256e7e4a6cb7677308c01 (patch) | |
tree | 617fe77b2cef3722235825619394c4f28e736caa | |
parent | beba6263667d6d5b69d562bedd36d0b3a5961c67 (diff) | |
download | pyinotify-5070c603a73ab911703256e7e4a6cb7677308c01.tar.gz |
- Fixed chain of classes including ChainIfTrue (reported by Matt Brown0.8.4
deadguysfrom@gmail.com)
- Reverted exception handling modifications
- Documentation
-rw-r--r-- | chain.py | 1 | ||||
-rwxr-xr-x | pyinotify.py | 18 | ||||
-rw-r--r-- | stats.py | 1 | ||||
-rw-r--r-- | transient_file.py | 12 |
4 files changed, 21 insertions, 11 deletions
@@ -1,5 +1,6 @@ # Example # +# This example logs the observed events into a log file. from pyinotify import * diff --git a/pyinotify.py b/pyinotify.py index 9a3255e..fc530ca 100755 --- a/pyinotify.py +++ b/pyinotify.py @@ -86,7 +86,7 @@ import ctypes.util __author__ = "seb@dbzteam.org (Sebastien Martini)" -__version__ = "0.8.3" +__version__ = "0.8.4" __metaclass__ = type # Use new-style classes by default @@ -109,7 +109,6 @@ console_handler = logging.StreamHandler() console_handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) log.addHandler(console_handler) log.setLevel(20) -log.propagate = False # Try to speed-up execution with psyco @@ -770,9 +769,14 @@ class ProcessEvent(_ProcessEvent): def __call__(self, event): stop_chaining = False if self.pevent is not None: + # By default methods return None so we fix as guideline + # that methods asking for stop chaining must explicitely + # return non None or False values, otherwise the default + # behavior is to chain call to the corresponding local + # method. stop_chaining = self.pevent(event) if not stop_chaining: - _ProcessEvent.__call__(self, event) + return _ProcessEvent.__call__(self, event) def nested_pevent(self): return self.pevent @@ -788,7 +792,7 @@ class ProcessEvent(_ProcessEvent): print(repr(event)) -class ChainIf(ProcessEvent): +class ChainIfTrue(ProcessEvent): """ Makes conditional chaining depending on the result of the nested processing instance. @@ -1127,8 +1131,8 @@ class Notifier: # Stop monitoring self.stop() break - except: - log.error("Exception caught while processing event") + except Exception, err: + log.error(err) def stop(self): """ @@ -1679,7 +1683,7 @@ class WatchManager: def cmp_name(event): return basename == event.name return self.add_watch(dirname, mask, - proc_fun=proc_class(ChainIf(func=cmp_name)), + proc_fun=proc_class(ChainIfTrue(func=cmp_name)), rec=False, auto_add=False, do_glob=False) @@ -1,5 +1,6 @@ # Example # +# Prints statistics. from pyinotify import * diff --git a/transient_file.py b/transient_file.py index f243169..3ab45cf 100644 --- a/transient_file.py +++ b/transient_file.py @@ -1,5 +1,7 @@ # Example # +# Permit to watch a transient file, run this code, then run +# transient_file.sh in another shell. from pyinotify import * @@ -11,14 +13,16 @@ class ProcessTransientFile(ProcessEvent): def process_default(self, event): # Implicitely IN_CREATE and IN_DELATE are watched too. You can - # ignore them and provide an empty process_default or you process them, - # either with process_default or their dedicated method - # (process_IN_CREATE, process_IN_DELETE), which will override - # process_default. + # ignore them and provide an empty process_default or you can + # process them, either with process_default or their dedicated + # method (process_IN_CREATE, process_IN_DELETE) which would + # override process_default. print 'default: ', event.maskname wm = WatchManager() notifier = Notifier(wm) +# In this case you must give the class object (ProcessTransientFile) +# as last parameter not a class instance. wm.watch_transient_file('/tmp/test1234', IN_MODIFY, ProcessTransientFile) notifier.loop() |