Exemplo n.º 1
0
    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.")
Exemplo n.º 2
0
    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.")
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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.")
Exemplo n.º 5
0
    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.")
Exemplo n.º 6
0
    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.")