Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitoring a single file

I need to monitor (using watchdog) a single file, not a whole directory.

What is the best way to avoid monitoring a whole directory? I suppose this

class watchdog.events.PatternMatchingEventHandler(patterns=None, ignore_patterns=None, ignore_directories=False, case_sensitive=False)[source]

could be helpful, but how to define an appropriate pattern for my file (C:/dir1/dir2/file.txt)?

like image 926
Tom Cruise Avatar asked Apr 28 '13 09:04

Tom Cruise


2 Answers

If you want to watch a file path like C:/dict1/dict2/file.txt, I think that's your pattern right there. There are no wildcards in, so it should be usable as-is.

As an aside, if Watchdog is giving you trouble, you could also consider Pyinotify: https://github.com/seb-m/pyinotify

like image 84
John Zwinck Avatar answered Sep 22 '22 05:09

John Zwinck


The way to provide patterns for PatternMatchingEventHandler is

 from watchdog.events import PatternMatchingEventHandler

 class MyHandler(PatternMatchingEventHandler):
     patterns = ["*.xml", "*.log", "*/test.txt"] # */test.txt to watch that specifi file
like image 43
ravi404 Avatar answered Sep 18 '22 05:09

ravi404