| Line | |
|---|
| 1 | # Example |
|---|
| 2 | # |
|---|
| 3 | import pyinotify |
|---|
| 4 | import os |
|---|
| 5 | |
|---|
| 6 | excl_file = os.path.join(os.getcwd(), 'exclude.patterns') |
|---|
| 7 | |
|---|
| 8 | wm = pyinotify.WatchManager() |
|---|
| 9 | notifier = pyinotify.Notifier(wm) |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | ### Method 1: |
|---|
| 13 | # Exclude filter object |
|---|
| 14 | excl = pyinotify.ExcludeFilter({excl_file: ('excl_lst1', 'excl_lst2')}) |
|---|
| 15 | # Add watches |
|---|
| 16 | wm.add_watch(['/etc/*', '/var'], pyinotify.ALL_EVENTS, |
|---|
| 17 | rec=True, do_glob=True, exclude_filter=excl) |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | ### Method 2 (Equivalent) |
|---|
| 21 | wm.add_watch('/etc/*', pyinotify.ALL_EVENTS, rec=True, do_glob=True, |
|---|
| 22 | exclude_filter=pyinotify.ExcludeFilter({excl_file:('excl_lst1',)})) |
|---|
| 23 | wm.add_watch('/var', pyinotify.ALL_EVENTS, rec=True, |
|---|
| 24 | exclude_filter=pyinotify.ExcludeFilter({excl_file:('excl_lst2',)})) |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | notifier.loop() |
|---|