3 from watchdog.events import FileSystemEventHandler
4 from watchdog.observers import Observer
6 class DirTrigger(FileSystemEventHandler):
10 def __init__(self, dir_path):
11 self._got_event = False
12 self._last_event_time = 0.0
13 self._last_reset_time = 0.0
14 self._lock = threading.Lock()
15 self._observer = Observer()
16 self._observer.schedule(self, path=dir_path, recursive=True)
19 self._observer.start()
24 def is_triggering(self):
27 return ( self._got_event and
28 (time.time() - self._last_event_time > DirTrigger.COOL_TIME) ) or \
29 time.time() - self._last_reset_time > DirTrigger.MAX_TIME
34 self._got_event = False
35 self._last_reset_time = time.time()
37 def on_any_event(self, event):
40 self._got_event = True
41 self._last_event_time = time.time()