4

で時計を作成しています

/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()

ウォッチ内にウォッチを作成するアプローチが正しい場合、ファイルを見つけたら内部ウォッチを停止するにはどうすればよいですか?

4

0 に答える 0