#!/usr/bin/python

import sys
try: import inotify
except:
	raise
	sys.stderr.write("Cannot import the inotify module\n")
	sys.stderr.flush()
	sys.exit(3)

watcher = inotify.Watcher()

import sys

if len(sys.argv) == 1:
	s = "inotify: a command-line client for Linux inotify. Watches specified filenames for filesystem events, and prints events to standard output.\n\nusage: inotify <files or directories to watch>\n"
	sys.stderr.write(s)
	sys.stderr.flush()
	sys.exit(2)

files = sys.argv[1:]

for file in files:
	try: watcher.watch(file)
	except Exception,e:
		print "Error watching %s: %s"%(file,str(e))
		sys.exit(1)

import time
import Queue
while True:
	try:
		event = watcher.get_next_event(True,1.0)
 		print event.as_string()
	except Queue.Empty:pass
	except KeyboardInterrupt:
# 		watcher._dump()
		sys.exit(0)
