Refactor CallbackEventHandler to be a PatternMatchingEventHandler

This commit is contained in:
Kristóf Tóth 2018-03-05 16:57:50 +01:00
parent d88728bb71
commit 02bc317009

View File

@ -1,11 +1,11 @@
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import PatternMatchingEventHandler
from os.path import dirname from os.path import dirname
class CallbackEventHandler(FileSystemEventHandler): class CallbackEventHandler(PatternMatchingEventHandler):
def __init__(self, *callbacks): def __init__(self, files, *callbacks):
super().__init__() super().__init__(files)
self.callbacks = callbacks self.callbacks = callbacks
def on_modified(self, event): def on_modified(self, event):
@ -20,7 +20,8 @@ class HistoryMonitor:
self._last_length = len(self._history) self._last_length = len(self._history)
self._callbacks = [] self._callbacks = []
self.observer = Observer() self.observer = Observer()
self.observer.schedule(CallbackEventHandler(self._fetch_history, self.observer.schedule(CallbackEventHandler([self.histfile],
self._fetch_history,
self._invoke_callbacks), self._invoke_callbacks),
dirname(self.histfile)) dirname(self.histfile))