/usr/share/doc/python-pyinotify-doc/examples/exclude.py is in python-pyinotify-doc 0.9.4-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Example: exclude items from being monitored.
#
import os
import pyinotify
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm)
### Method 1:
# Exclude patterns from file
excl_file = os.path.join(os.getcwd(), 'exclude.lst')
excl = pyinotify.ExcludeFilter(excl_file)
# Add watches
res = wm.add_watch(['/etc/hostname', '/etc/cups', '/etc/rc0.d'],
pyinotify.ALL_EVENTS, rec=True, exclude_filter=excl)
### Method 2 (Equivalent)
# Exclude patterns from list
excl_lst = ['^/etc/apache[2]?/',
'^/etc/rc.*',
'^/etc/hostname',
'^/etc/hosts',
'^/etc/(fs|m)tab',
'^/etc/cron\..*']
excl = pyinotify.ExcludeFilter(excl_lst)
# Add watches
res = wm.add_watch(['/etc/hostname', '/etc/cups', '/etc/rc0.d'],
pyinotify.ALL_EVENTS, rec=True, exclude_filter=excl)
#notifier.loop()
|