def _get_node_name_path(self, nodeid): """Returns the path of the nodeid""" path = self._path_cache.get_path_list(nodeid) if path is None and self._index: # fallback to index path = [self._filename] + self._index.get_node_filepath(nodeid) if path is None: raise UnknownNode(nodeid) return path
def get_node_basename(self, nodeid): """Returns the basename of the node""" basename = self._path_cache.get_basename(nodeid) if basename is None and self._index: # fallback to index node = self._index.get_node(nodeid) if node: basename = node["basename"] if basename is None: raise UnknownNode(nodeid) return basename
def _get_node_path(self, nodeid): """Returns the path of the nodeid""" path = self._path_cache.get_path(nodeid) if path is None and self._index: # fallback to index path_list = self._index.get_node_filepath(nodeid) if path_list is not None: path = os.path.join(self._filename, *path_list) if path is None: raise UnknownNode(nodeid) return path
def add(self, nodeid, basename, parentid): """Add a new nodeid, basename, and parentid to the cache""" parent = self._nodes.get(parentid, 0) if parent is 0: # TODO: should I allow unknown parent? raise UnknownNode("unknown parent %s" % repr( (basename, parentid, self._nodes))) node = self._nodes.get(nodeid, None) if node: node.parent = parent node.basename = basename else: node = self._nodes[nodeid] = PathCacheNode(nodeid, basename, parent) if parent: parent.children.add(node)