import pyinotify import os for event in dir(pyinotify.EventsCodes): if type(getattr(pyinotify.EventsCodes,event)) == int: globals()[event]=getattr(pyinotify.EventsCodes,event) watches=( { 'path':'/home/lefti/pokus/', 'chmod':100, 'chown':18, #'events':IN_ATTRIB|IN_CREATE, 'events':IN_ATTRIB|IN_CREATE, }, { 'path':'/home/lefti/pokus/sub/', 'user':1000, 'group':100, 'file_perm':770, #'events':IN_ATTRIB|IN_CREATE|IN_MOVED_TO|IN_DONT_FOLLOW, 'events':IN_ATTRIB, 'chroot':True, 'setgid':100, 'setuid':1000, }, ) #paths=[] #for watch in watches: # paths.append(watch['path']) #import re,os #for path in paths: # tmpre=re.compile('%s.*' % path) # for ppath in paths: # if re.match(tmpre,ppath) and ppath!=path: # print "TODO!!!" # os.sys.exit() #co je dal to ma vetsi prioritu, hmm #print watches[0] #print watches[1] def process(event): if event.event_name=='IN_CREATE': print '~/pokus/' #print "path:%s name:%s event_name:%s mask:%s wd:%s" % (event.path,event.name,event.event_name,event.mask,event.wd) wm=pyinotify.WatchManager() for watch in watches: pid=os.fork() if pid>0 wm.add_watch(watch['path'],watch['events'],process,rec=True,auto_add=True) notifier=pyinotify.Notifier(wm) print "Inotify checker is ready" try: while True: notifier.process_events() if notifier.check_events(): notifier.read_events() except KeyboardInterrupt: notifier.close() print "exiting..."