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