Structural modifications
* pyinotify.py is now a standalone file.
* The namespace is reduced to `pyinotify`. Thus, you access everything from `pyinotify`, For instance accessing `max_user_instances` attribute :
sh
>>> import pyinotify
>>> pyinotify.max_user_watches
<max_user_watches=524288>
>>> pyinotify.max_user_watches.value
524288
>>> pyinotify.max_user_watches.value = 42
>>> pyinotify.max_user_watches.value
42
* Likewise, events names are directly accessible at pyinotify's scope eg: `pyinotify.IN_MODIFY`.
* Event instances provide a new attribute: `an_event.pathname`. Example: `<Event dir=False mask=0x100 maskname=IN_CREATE name=foo path=/tmp pathname=/tmp/foo wd=1>`
Chaining several processing functions together
* ProcessEvent instances can be chained together, see [[chain.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/chain.py]].
Debugging and statistics
* The [[logging module|http://docs.python.org/library/logging.html]] is used for debugging and logging errors, it can be accessed through `pyinotify.log` and its level set with `log.setLevel(level)` (by default the level is set to 20 when pyinotify is imported and is set to 10 when it is executed from command line
python
import pyinotify
[...]
Modify logging level
pyinotify.log.setLevel(10)
output debug message
pyinotify.log.debug('debug msg2')
* There is a tiny functionality available to display statistics see new option `-s` (from command line) and this example [[stats.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/stats.py]], which has given this output
New method `Notifier.loop()`
* `Notifier` now provides a `loop()` method (the former pattern `while True: ...` is now useless), see [[loop.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/loop.py]].
Policy for reading events
* `select.poll` timeout's value is set to `None` when called from `Notifier` and `ThreadedNotifier`.
* `Notifier's` constructor accepts `read_freq`, `threshold` and `timeout` as parameters, for specifying at which frequency and when to read new events. `read_freq` sets the minimal period of time between two read of events (0s by default), sleeping during the rest of time. `threshold` is the minimal size (0 byte by default) of accumulated events needed before processing the queue (must be used in combination with `read_freq`, read the docstrings for more details). `timeout` is the parameter given to `select.poll`.
python
examples:
n = Notifier(wm, read_freq=0, threshold=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, threshold=512) read events every 5s if size to read is >= 512 bytes
Functionality for helping watch transient files
* Supports simplified watch of transient files (for instance for watching pid files `/var/run/myapp.pid`), see [[transient_file.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/transient_file.py]], [[transient_file.sh|http://github.com/seb-m/pyinotify/tree/master/python2/examples/transient_file.sh]].
Daemonize pyinotify
* Ability to detach and daemonize Notifier instances, see [[daemon.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/daemon.py]]
python
notifier.loop(daemonize=True) By default writes its pid to /var/run/<scriptname>.pid
Exclude files from being watched
* `WatchManager` and `.add_watch` support an exclusion path filter: a boolean function can optionally be called each time a new path is about to be watched, if this predicate returns `True` this path is excluded (i.e. not watched).
* See how it works through this example [[exclude.lst|http://github.com/seb-m/pyinotify/tree/master/python2/examples/exclude.lst]] and [[exclude.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/exclude.py]].
Various improvements
* There is a way to delegate initialization to `my_init(*kargs)` when `ProcessEvent's` subclass is instantiated. Override this method in your subclass for achieving custom initialization. Moreover, you must instantiate your class with keyworded arguments, see the following example [[chain.py|http://github.com/seb-m/pyinotify/tree/master/python2/examples/chain.py]].
python
class Log(ProcessEvent):
def my_init(self, pathname):
self._fileobj = file(pathname, 'w')
[...]
notifier = Notifier(wm, Empty(TrackMofications(Log(pathname=f)), msg='outer'))
* Accepts a New option `-e` list,of,events,separated,with,commas. It works like this `python pyinotify.py -e IN_CREATE,IN_DELETE`