mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-26 05:11:32 +00:00
Refactor CallbackEventHandler to be a PatternMatchingEventHandler
This commit is contained in:
parent
d88728bb71
commit
02bc317009
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user