Skip to content

Instantly share code, notes, and snippets.

@adamwg
Created March 1, 2012 19:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamwg/1952483 to your computer and use it in GitHub Desktop.
Save adamwg/1952483 to your computer and use it in GitHub Desktop.
inotify for notmuch
# Example: loops monitoring events forever.
#
import pyinotify
from os import system
from time import sleep
def run_nm(notifier):
sleep(1)
system("notmuch new")
return False
# Instanciate a new WatchManager (will be used to store watches).
wm = pyinotify.WatchManager()
# Associate this WatchManager with a Notifier (will be used to report and
# process events).
notifier = pyinotify.Notifier(wm)
# Add a new watch on /tmp for ALL_EVENTS.
wm.add_watch('/home/gordoa4/mail',
pyinotify.IN_CREATE | pyinotify.IN_DELETE |
pyinotify.IN_MODIFY | pyinotify.IN_MOVE_SELF |
pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO,
rec=True, auto_add=True,
exclude_filter=lambda x: '.notmuch' in x)
# Loop forever and handle events.
notifier.loop(daemonize=False, callback=run_nm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment