habe hier ein stück code das die veränderung einer datei überwacht. würde jetzt gerne einen test dazu schreiben.
aber wie mancht man das am besten?
habe den verdacht das die methode IN_CLOSE_WRITE teilweise mehr als ein "close" ausgibt.
wie kommt man an die ausgabe von print zur überprüfung? oder wie baut man den code so um das es einen rückgabewert gibt mit dem gearbeitet werden kann?
die mthode: IN_CLOSE... wird ja von python irgendwo aufgerufen
Code: Alles auswählen
import pyinotify
class OnWriteHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
print "close"
def watch(file):
wm = pyinotify.WatchManager()
# Instanciate a new WatchManager (will be used to store watches).
handler = OnWriteHandler()
notifier = pyinotify.Notifier(wm, default_proc_fun=handler)
# Associate this WatchManager with a Notifier (will be used to report and
# process events).
wm.add_watch(file, pyinotify.ALL_EVENTS)
# Loop forever and handle events.
notifier.loop()
if __name__ == '__main__':
import optparse, os
parser = optparse.OptionParser()
parser.add_option('-f', '--file', help='pcap capture file', dest='file', action='store')
(opts, args) = parser.parse_args()
watch(opts.file)