Last active
August 29, 2015 14:06
-
-
Save lvidarte/acede59ccffda41541e2 to your computer and use it in GitHub Desktop.
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
import sys | |
import pyinotify | |
from datetime import datetime | |
wm = pyinotify.WatchManager() | |
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | |
files = {} | |
class EventHandler(pyinotify.ProcessEvent): | |
def process_IN_CREATE(self, event): | |
start = datetime.now() | |
files[event.name] = start | |
print "Creating:", event.name, str(start) | |
def process_IN_DELETE(self, event): | |
delta = datetime.now() - files[event.name] | |
del files[event.name] | |
print "Removing:", event.name, str(delta) | |
handler = EventHandler() | |
notifier = pyinotify.Notifier(wm, handler) | |
wdd = wm.add_watch(sys.argv[1], mask, rec=True) | |
notifier.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment