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