def getStoreFromEvent(self, event): path = os.fsdecode(event.src_path) if match_any_paths([path], included_patterns=self.patterns, excluded_patterns=self.ignore_patterns, case_sensitive=self.case_sensitive): return self.createStore(self.factory, path)
def match_file(self, path): """Check if the path matches the patterns and folder""" return match_any_paths( [path], included_patterns=self.patterns, excluded_patterns=self.ignore_patterns, case_sensitive=self.case_sensitive, )
def dispatch(self, event): """Dispatches events to the appropriate methods. :param event: The event object representing the file system event. :type event: :class:`FileSystemEvent` """ if self.ignore_directories and event.is_directory: return paths = [] if hasattr(event, 'dest_path'): paths.append(os.fsdecode(event.dest_path)) if event.src_path: paths.append(os.fsdecode(event.src_path)) if match_any_paths(paths, included_patterns=self.patterns, excluded_patterns=self.ignore_patterns, case_sensitive=self.case_sensitive): super().dispatch(event)
def on_moved(self, event): """ Called when a file or a directory is moved or renamed. Many editors don't directly change a file, instead they make a transitional file like ``*.part`` then move it to the final filename. Arguments: event: Watchdog event, either ``watchdog.events.DirMovedEvent`` or ``watchdog.events.FileModifiedEvent``. """ # We are only interested for the destination if match_any_paths( [event.dest_path], included_patterns=self.patterns, excluded_patterns=self.ignore_patterns, case_sensitive=self.case_sensitive, ): msg = "Change detected from a move on: {}" self.logger.debug(msg.format(event.dest_path)) return self.build_for_item(event.dest_path) return []
def test_match_any_paths(included_patterns, excluded_patterns, case_sensitive, expected): pathnames = {"/users/gorakhargosh/foobar.py", "/var/cache/pdnsd.status", "/etc/pdnsd.conf", "/usr/local/bin/python"} assert match_any_paths(pathnames, included_patterns, excluded_patterns, case_sensitive) == expected