我正在创建一个手表
/temp
目录。 我想在这个目录中查看任何新目录,比如
/temp/dir1, /temp/dir2, temp/dir3.
我想观看创建的新目录,寻找像"提交"并采取必要的行动。
现在我在/ temp目录上创建一个监视器,在IN_CREATE事件中我检查它是否是一个目录,如果它是我在找到的新目录上放了一个新监视并调用另一个事件处理程序。
代码:
import asyncore
import pyinotify
wm = pyinotify.WatchManager() # Watch Manager
mask = pyinotify.IN_CREATE # watched events
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
print "dir: ", event.dir
print "Creating now: ", event.pathname
print "Event Path: ", event.path
print "Event name: ", event.name
new_notifier = pyinotify.AsyncNotifier(wm, EventHandlerForNewDir())
if event.dir:
print "Setting up second watch"
wdd2 = wm.add_watch(event.pathname, mask, rec=True)
new_notifier.loop()
class EventHandlerForNewDir(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
print "dir: ", event.dir
print "Creating now: ", event.pathname
print "Event Path: ", event.path
print "Event name: ", event.name
if (event.name == 'submit' and not (event.dir)):
print "You are Awesome"
notifier = pyinotify.AsyncNotifier(wm, EventHandler())
wdd = wm.add_watch('/temp', mask, rec=True)
notifier.loop()
如果在手表内创建手表的方法是正确的,那么找到文件后如何停止内部手表?