Tutorial: advanced use of watchdog in Python : excluding files — a git auto commit example (part II)
In part I, the event handler that we have created monitors all files in a given folder.
What if I want to exclude some files or folders ?
Let’s take another look at the auto-push git example of part I. Now I want to ignore file changes in the .git folder, since each time we make a commit the folder will be updated, creating an infinite loop of file changes notification.
Here I used watchdog’s RegexMatchingEventHandler module which matches given regexes with file paths associated with occurring events.
from watchdog.events import RegexMatchingEventHandler
And when I create my event handler, instead of supervising all files with “*” pattern (this snippet comes from part I)
I tell my handler to ignore all paths that begin with “./.git” using regular expression.
Tada! Now our git example is complete ! Enjoy your watchdog :)