#!/usr/bin/env python


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

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: inotify.watch(file)
	except Exception,e:
		print "Error watching %s: %s"%(file,str(e))
		sys.exit(1)

try:
	while True:
		events = inotify.get_pending_events(block=True)
		for event in events: print event.as_string()
except KeyboardInterrupt: sys.exit(0)
