diff --git a/lib/tfw/components/inotify/inotify.py b/lib/tfw/components/inotify/inotify.py index f26ce6b..2cf9523 100644 --- a/lib/tfw/components/inotify/inotify.py +++ b/lib/tfw/components/inotify/inotify.py @@ -64,21 +64,21 @@ class InotifyDirDeletedEvent(InotifyEvent): class InotifyObserver: - def __init__(self, path, patterns=None, exclude=None): + def __init__(self, path, patterns=None, exclude=None, recursive=False): self._path = path self._patterns = patterns self._exclude = exclude self.observer = Observer() - self.reset(path, patterns, exclude) + self._reset(path, patterns, exclude) - def reset(self, path, patterns, exclude): + def _reset(self, path, patterns, exclude): dispatch_event = self.dispatch_event class TransformerEventHandler(PatternMatchingEventHandler): def on_any_event(self, event): dispatch_event(event) self.handler = TransformerEventHandler(patterns, exclude) self.observer.unschedule_all() - self.observer.schedule(self.handler, path, recursive=True) + self.observer.schedule(self.handler, path, recursive) @property def path(self): @@ -87,7 +87,7 @@ class InotifyObserver: @path.setter def path(self, path): self._path = path - self.reset(path, self._patterns, self._exclude) + self._reset(path, self._patterns, self._exclude) @property def patterns(self): @@ -96,7 +96,7 @@ class InotifyObserver: @patterns.setter def patterns(self, patterns): self._patterns = patterns - self.reset(self._path, patterns, self._exclude) + self._reset(self._path, patterns, self._exclude) @property def exclude(self): @@ -105,7 +105,7 @@ class InotifyObserver: @exclude.setter def exclude(self, exclude): self._exclude = exclude - self.reset(self._path, self._patterns, exclude) + self._reset(self._path, self._patterns, exclude) def start(self): self.observer.start() diff --git a/lib/tfw/components/inotify/test_inotify.py b/lib/tfw/components/inotify/test_inotify.py index 702e2c7..6b4bdb3 100644 --- a/lib/tfw/components/inotify/test_inotify.py +++ b/lib/tfw/components/inotify/test_inotify.py @@ -66,10 +66,10 @@ class InotifyContext: class InotifyTestObserver(InotifyObserver): - def __init__(self, path, patterns=None, exclude=None): + def __init__(self, path, patterns=None, exclude=None, recursive=False): self.any_list = [] self.create_queue, self.modify_queue, self.move_queue, self.delete_queue = [Queue() for _ in range(4)] - super().__init__(path, patterns, exclude) + super().__init__(path, patterns, exclude, recursive) def on_any_event(self, event): self.any_list.append(event) @@ -99,7 +99,7 @@ def context(): mkdir(newdir) Path(join(newdir, generate_name()+'.txt')).touch() - monitor = InotifyTestObserver(workdir) + monitor = InotifyTestObserver(workdir, recursive=True) monitor.start() yield InotifyContext(workdir, monitor)