def ReadDbRoot(self, path, layer_id):
        """Returns dbroot.

    If dbroot is not found, throws an exception.

    Args:
      path: path to dbRoot file to use. If not found uses first qtp packet.
      layer_id: id of layer in the composite globe.
    Returns:
      The dbroot.
    Raises:
      PortableException: if unknown or unreadable glx.
      UnableToFindException: if unable to find a dbroot.
    """
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        if self.unpacker_.FindLayerFile(path, layer_id, self.file_loc_):
            data = self._GetData()
            print "path dbroot: ", path, len(data)
            return data
        elif self.unpacker_.FindQtpPacket("0", glc_unpacker.kDbRootPacket, 0,
                                          layer_id, self.file_loc_):
            return self._GetData()
        else:
            print "Did not find dbRoot for: ", layer_id
            raise portable_exceptions.UnableToFindException(
                "Unable to find dbroot.")
    def ReadMapDataPacket(self, qtpath, packet_type, channel, layer_id):
        """Returns packet at given address and channel.

    If packet is not found, throws an exception.

    Args:
      qtpath: the quadtree node of the map packet.
      packet_type: the type of data in the map packet.
      channel: the channel of the map packet.
      layer_id: id of layer in the composite globe.
    Returns:
      The map packet itself.
    Raises:
      PortableException: if unknown or unreadable glx.
      UnableToFindException: if unable to find the map data packet.
    """
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        if self.unpacker_.FindMapDataPacket(qtpath, packet_type, channel,
                                            layer_id, self.file_loc_):
            return self._GetData()
        else:
            raise portable_exceptions.UnableToFindException(
                "Unable to find packet.")
    def ReadFile(self, relative_file_path):
        """Returns content of file stored in globe package file.

    If file is not found, returns an empty string.

    Args:
      relative_file_path: Relative path to file within glx.
    Returns:
      Data from the file within the glx.
    Raises:
      PortableException: if unknown or unreadable glx.
      UnableToFindException: if unable to find specified file.
    """
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        relative_file_path = relative_file_path.encode("ascii", "ignore")
        # print "FindFile", relative_file_path
        if self.unpacker_.FindFile(relative_file_path, self.file_loc_):
            # print "Found file", self.file_loc_.Offset()
            return self._GetData()
        else:
            raise portable_exceptions.UnableToFindException(
                "Unable to find file %s." % relative_file_path)
    def FileExists(self, relative_file_path):
        """Returns whether file exists in current glx."""
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        relative_file_path = relative_file_path.encode("ascii", "ignore")
        return self.unpacker_.FindFile(relative_file_path, self.file_loc_)
    def ServeGlobe(self, globe_path):
        """Sets local or remote globe to be served."""
        if globe_path[-4:] == ".glb" or globe_path[-4:] == ".glm":
            self.is_local_ = True
            self.ServeLocalGlobe(globe_path, False)
        elif globe_path[-4:] == ".glc":
            self.is_local_ = True
            self.ServeLocalGlobe(globe_path, True)
        elif globe_path[-4:] == ".glr":
            self.is_local_ = False
            self.LoadGlr(globe_path)
        else:
            raise portable_exceptions.PortableException(
                "Unknown file type: %s" % globe_path)

        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % globe_path)

        self.SetType(globe_path)
    def ReadMetaDbRoot(self):
        """Reads meta dbroot.

    Returns:
      meta dbroot if found, otherwise throws an exception.
    Raises:
      PortableException: if unknown or unreadable glx.
      UnableToFindException: if unable to find meta dbroot.
    """
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        if self.unpacker_.FindMetaDbRoot(self.file_loc_):
            return self._GetData()
        else:
            raise portable_exceptions.UnableToFindException(
                "Unable to find meta dbroot.")
 def SetType(self, globe_name):
     """Sets is2d based on the given globe name."""
     self.is_gee_ = self.unpacker_.IsGee()
     if globe_name[-4:] == ".glb":
         self.is_2d_ = False
         self.is_3d_ = True
         self.is_composite_ = False
         self.SetDbrootInfo()
     elif globe_name[-4:] == ".glm":
         self.is_2d_ = True
         self.is_3d_ = False
         self.is_composite_ = False
     elif globe_name[-4:] == ".glc":
         self.is_2d_ = self.unpacker_.Is2d()
         self.is_3d_ = self.unpacker_.Is3d()
         self.is_composite_ = True
         if self.is_3d_:
             self.SetDbrootInfo()
     else:
         raise portable_exceptions.PortableException(
             "Unknown file type: %s" % globe_name)
    def ReadQtPacket(self, qtpath, layer_id):
        """Returns quadtree packet at given address.

    If quadtree packet is not found, throws an exception.
    Args:
      qtpath: the quadtree node of the quad set packet.
      layer_id: id of layer in the composite globe.
    Returns:
      The quadtree packet itself.
    Raises:
      PortableException: if unknown or unreadable glx.
      UnableToFindException: if unable to find the quad set packet.
    """
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        if self.unpacker_.FindQtpPacket(qtpath, glc_unpacker.kQtpPacket, 0,
                                        layer_id, self.file_loc_):
            return self._GetData()
        else:
            raise portable_exceptions.UnableToFindException(
                "Unable to find quadtree packet.")
    def ReadLayerFile(self, relative_file_path, layer_id):
        """Returns content of file stored in layer package file.

    If file is not found, returns an empty string.
    Args:
      relative_file_path: relative path to file in the layer.
      layer_id: id of layer in the composite globe.
    Returns:
      The file content.
    Raises:
      PortableException: if unknown or unreadable glx.
      UnableToFindException: if unable to find the specified file.
    """
        if not self.unpacker_:
            raise portable_exceptions.PortableException(
                UNKOWN_OR_UNREADABLE_GLX_ERROR_MSG % self.globe_name_)

        if self.unpacker_.FindLayerFile(relative_file_path, layer_id,
                                        self.file_loc_):
            return self._GetData()
        else:
            raise portable_exceptions.UnableToFindException(
                "Unable to find file.")