mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:31:33 +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.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))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user