#!/usr/bin/env python
import gamin
import time
from select import select
def callback(path, event):
# The "event" argument here is one of the integer values from the DATA section of 'pydoc gamin'
print "Got callback: %s, %s" % (path, event)
mon = gamin.WatchMonitor()
mon.watch_directory(".", callback)
# Get a file descriptor so we can watch for communication of new events simply
fd=mon.get_fd()
# Loop forever
while True:
# Watch the file descriptor from above for new data incoming
# See pydoc select.select for more
select([fd],[],[])
# Crunch through the events and call the callback
ret = mon.event_pending()
if ret > 0:
ret = mon.handle_one_event()
ret = mon.handle_events()
# Never reached, as the above is a "loop forever"
mon.stop_watch(".")
del mon