def _u_find_id_from_manifest(self, id, manifest, revision=None): """Search for the relative path to id using manifest, a list of all files. Returns None if the id is not found. """ be_dir = self._cached_path_id._spacer_dirs[0] be_dir_sep = self._cached_path_id._spacer_dirs[0] + os.path.sep files = [f for f in manifest if f.startswith(be_dir_sep)] for file in files: if not file.startswith(be_dir + os.path.sep): continue parts = file.split(os.path.sep) dir = parts.pop(0) # don't add the first spacer dir for part in parts[:-1]: dir = os.path.join(dir, part) if not dir in files: files.append(dir) for file in files: try: p_id = self._u_path_to_id(file) if p_id == id: return file except (SpacerCollision, InvalidPath): pass raise InvalidID(id, revision=revision)
def path(self, id, relpath=False): fields = id.split('/', 1) uuid = fields[0] if len(fields) == 1: extra = [] else: extra = fields[1:] if uuid not in self._cache: self.init(cache=self._cache) if uuid not in self._cache: raise InvalidID(uuid) if relpath == True: return os.path.join(self._cache[uuid], *extra) return os.path.join(self._root, self._cache[uuid], *extra)
def _u_find_id(self, id, revision): """Search for the relative path to id as of revision. Returns None if the id is not found. """ assert self._rooted == True be_dir = self._cached_path_id._spacer_dirs[0] stack = [(be_dir, be_dir)] while len(stack) > 0: path, long_id = stack.pop() if long_id.endswith('/' + id): return path if self._vcs_isdir(path, revision) == False: continue for child in self._vcs_listdir(path, revision): stack.append((os.path.join(path, child), '/'.join([long_id, child]))) raise InvalidID(id, revision=revision)
def __init__(self, pathname, root='.'): path = os.path.abspath(os.path.join(root, pathname)) InvalidID.__init__(self, 'No such file: %s' % path)
def __init__(self, path, root, msg=None, **kwargs): if msg == None: msg = 'Path "%s" not in root "%s"' % (path, root) InvalidID.__init__(self, msg=msg, **kwargs) self.path = path self.root = root
children[i] = self._u_path_to_id(cpath) return [c for c in children if c != None] def _get(self, id, default=libbe.util.InvalidObject, revision=None): try: relpath = self.path(id, revision, relpath=True) contents = self._vcs_get_file_contents(relpath, revision) except InvalidID, e: if default == libbe.util.InvalidObject: raise e return default if contents in [libbe.storage.base.InvalidDirectory, libbe.util.InvalidObject] \ or len(contents) == 0: if default == libbe.util.InvalidObject: raise InvalidID(id, revision) return default return contents def _set(self, id, value): try: path = self._cached_path_id.path(id) except InvalidID, e: raise if not os.path.exists(path): raise InvalidID(id) if os.path.isdir(path): raise libbe.storage.base.InvalidDirectory(id) f = open(path, "wb") f.write(value) f.close()