Beispiel #1
0
 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)
Beispiel #2
0
    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")
Beispiel #3
0
 def __exit__(self, type, value, traceback):
     OBSERVER.unschedule(self, ".git")
Beispiel #4
0
 def __enter__(self):
     OBSERVER.schedule(self, ".git")
     if os.path.exists(self.lockfile):
         self._lock()
     return self
Beispiel #5
0
 def unwatch(self, storage):
     OBSERVER.unschedule(storage.handler, ".git")
Beispiel #6
0
 def unwatch(self):
     OBSERVER.unschedule(self, self._abs_root_dir).stop()