Created
January 22, 2013 02:23
-
-
Save caingougou/4591532 to your computer and use it in GitHub Desktop.
Monitor file or folder changes
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
#!/usr/bin/env python | |
import pyinotify | |
import sys | |
class MyEventHandler(pyinotify.ProcessEvent): | |
def process_IN_ACCESS(self, event): | |
print "ACCESS event:", event.pathname | |
def process_IN_ATTRIB(self, event): | |
print "ATTRIB event:", event.pathname | |
def process_IN_CLOSE_NOWRITE(self, event): | |
print "CLOSE_NOWRITE event:", event.pathname | |
def process_IN_CLOSE_WRITE(self, event): | |
print "CLOSE_WRITE event:", event.pathname | |
def process_IN_CREATE(self, event): | |
print "CREATE event:", event.pathname | |
def process_IN_DELETE(self, event): | |
print "DELETE event:", event.pathname | |
def process_IN_MODIFY(self, event): | |
print "MODIFY event:", event.pathname | |
def process_IN_OPEN(self, event): | |
print "OPEN event:", event.pathname | |
def main(): | |
# watch manager | |
wm = pyinotify.WatchManager() | |
wm.add_watch(sys.argv[1], pyinotify.ALL_EVENTS, rec=True) | |
# event handler | |
eh = MyEventHandler() | |
# notifier | |
notifier = pyinotify.Notifier(wm, eh) | |
notifier.loop() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment