-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed custom glob functions, uses standard glob module directly.
- Modified exclusion filter mechanism, patterns still can be loaded from files but the syntax has changed see exclude.lst for more details. This new method is safer since the external file is not executed anymore, it is only parsed looking for patterns loaded as strings.
- Loading branch information
Showing
5 changed files
with
80 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# File associated to exclude.py | ||
# | ||
# List of patterns using regexps as defined into re standard module. | ||
# These regexps are matched against submitted paths with re.match(). | ||
|
||
# Put only one pattern by line. | ||
^/etc/apache[2]?/ | ||
^/etc/rc.* | ||
^/etc/hostname | ||
^/etc/hosts | ||
^/etc/(fs|m)tab | ||
^/etc/cron\..* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
# Example: excludes items from being monitored. | ||
# Example: exclude items from being monitored. | ||
# | ||
import pyinotify | ||
import os | ||
|
||
excl_file = os.path.join(os.getcwd(), 'exclude.patterns') | ||
import pyinotify | ||
|
||
wm = pyinotify.WatchManager() | ||
notifier = pyinotify.Notifier(wm) | ||
|
||
|
||
### Method 1: | ||
# Exclude filter object | ||
excl = pyinotify.ExcludeFilter({excl_file: ('excl_lst1', 'excl_lst2')}) | ||
# Exclude patterns from file | ||
excl_file = os.path.join(os.getcwd(), 'exclude.lst') | ||
excl = pyinotify.ExcludeFilter(excl_file) | ||
# Add watches | ||
wm.add_watch(['/etc/*', '/var'], pyinotify.ALL_EVENTS, | ||
rec=True, do_glob=True, exclude_filter=excl) | ||
|
||
res = wm.add_watch(['/etc/hostname', '/etc/cups', '/etc/rc0.d'], | ||
pyinotify.ALL_EVENTS, rec=True, exclude_filter=excl) | ||
|
||
### Method 2 (Equivalent) | ||
wm.add_watch('/etc/*', pyinotify.ALL_EVENTS, rec=True, do_glob=True, | ||
exclude_filter=pyinotify.ExcludeFilter({excl_file:('excl_lst1',)})) | ||
wm.add_watch('/var', pyinotify.ALL_EVENTS, rec=True, | ||
exclude_filter=pyinotify.ExcludeFilter({excl_file:('excl_lst2',)})) | ||
|
||
# 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() | ||
#notifier.loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters