Structural modifications
Chaining several processing functions together
- ProcessEvent instances can be chained, see chain.py.
Debugging and statistics
- Use the logging module for errors and debugging. Every 'print' statements have been removed.
- Provides a processing class and a new option -s for displaying statistics about received events (can be chained of course), see stats.py, which give the following output:
New method Notifier.loop()
- Notifier now provides a loop() method (the former 'while True' is useless now), see loop.py.
Policy for reading events
- select.Poll timeout's value changed to None when called from Notifier and set to 10s when called from ThreadedNotifier.
- Notifier's constructor accepts read_freq, treshold and timeout as parameters, for specifying at which frequence and when to read new events. read_freq sets the minimal period of time between read of events (0s by default), sleeping during the rest of time. treshold is the minimal size (0 byte by default) of events needed before accepting read the queue (must be used in combination with read_freq read the docstrings fro more details). timeout is the parameter given to select.poll.
# examples:
n = Notifier(wm, read_freq=0, treshold=0, timeout=None) # values by default read events asap
n = Notifier(wm, read_freq=5) # read events every 5s
n = Notifier(wm, read_freq=5, treshold=512) # read events every 5s if size to read is >= 512 bytes
Functionality for helping watch transient files
Daemonize pyinotify
- Ability to detach and daemonize Notifier instances, see daemon.py
notifier.loop(daemonize=True) # By default writes pid to /var/run/<scriptname>.pid
Exclude files from being watched
- WatchManager and .add_watch support an exclude path filter, a boolean function called every time a new path is about to be watched, if this predicate returns True the path will eventually be excluded whereas if it returns False it will be watched.
- See how it works through an example exclude.patterns and exclude.py.
Various improvements
- Delegates initialization to my_init(*kargs) when ProcessEvent's subclass is instanciated. Override this method in your class for achieving custom initialization. Moreover, you must instantiate your class with keyword arguments, see the following example chain.py.
class Log(ProcessEvent):
def my_init(self, pathname):
self._fileobj = file(pathname, 'w')
[...]
notifier = Notifier(wm, Empty(TrackMofications(Log(pathname=f)), msg='outter'))
- Try to load psyco to speed-up pyinotify a little bit (the use of this module is optional, psyco is not mandatory), not sure if it really helps but at least it can't hurt.
- New option -e list,of,events,separated,with,commas. Example: python pyinotify.py -e IN_CREATE,IN_DELETE