def watch(self, callback): self._callback = callback root_dir = self.root_dir or git_dir() try: self._abs_root_dir = os.path.abspath(self.root_dir or git_dir()) except AttributeError: raise ValueError("root_dir inappropriate: %s" % repr(root_dir)) OBSERVER.schedule(self, self._abs_root_dir)
def watch(self, obj, storage, callback): root_dir = self._root_dir watching = self.substitute(obj, self._watching) class handler(watchdog.events.FileSystemEventHandler): def path_matches(self, rel_path): return any(fnmatch(rel_path, g) for g in watching) def on_any_event(self, event): if event.is_directory: pass elif self.path_matches(os.path.relpath(event.src_path, root_dir)): callback() else: try: if self.path_matches(os.path.relpath(event.dest_path, root_dir)): callback() except AttributeError: pass storage.handler = handler() OBSERVER.schedule(storage.handler, ".git")
def __exit__(self, type, value, traceback): OBSERVER.unschedule(self, ".git")
def __enter__(self): OBSERVER.schedule(self, ".git") if os.path.exists(self.lockfile): self._lock() return self
def unwatch(self, storage): OBSERVER.unschedule(storage.handler, ".git")
def unwatch(self): OBSERVER.unschedule(self, self._abs_root_dir).stop()