Ejemplo n.º 1
0
  def finish_dump(self):
    if self.compression_active:
      self.body_dumper.stop_compression()
      self.compression_active = False
    if self.encryption_active:
      self.body_dumper.stop_encryption()

    #
    # Serialize the body block table
    #
    body_table_io = StringIO.StringIO()
    body_blocks = self.body_dumper.get_blocks()
    serialize_blocks(body_table_io, body_blocks)
    body_table_str = body_table_io.getvalue()

    #
    # Serialize the header table
    #
    message = "Manent container %d of sequence '%s'" % (
      self.index, base64.urlsafe_b64encode(self.sequence_id))
    self.header_dumper.add_block(Digest.dataDigest(message),
                   CODE_CONTAINER_DESCRIPTOR, message)
    self.header_dumper.add_block(Digest.dataDigest(body_table_str),
                   CODE_BLOCK_TABLE, body_table_str)

    if self.encryption_active:
      self.header_dumper.stop_encryption()
      self.encryption_active = False

    header_blocks = self.header_dumper.get_blocks()
    header_table_io = StringIO.StringIO()
    serialize_blocks(header_table_io, header_blocks)
    header_table_str = header_table_io.getvalue()
    
    #
    # Write the header
    #
    assert self.header_file.tell() == 0
    self.header_file.write(MAGIC)
    Format.write_int(self.header_file, VERSION)
    Format.write_int(self.header_file, self.index)
    Format.write_int(self.header_file, len(header_table_str))
    self.header_file.write(Digest.dataDigest(header_table_str))
    self.header_file.write(header_table_str)
    header_dump_str = self.header_dump_os.getvalue()
    Format.write_int(self.header_file, len(header_dump_str))
    self.header_file.write(header_dump_str)
    logging.debug("Container %d has header of size %d" %
        (self.index, self.header_file.tell()))
Ejemplo n.º 2
0
def serialize_blocks(file, blocks):
  for (digest,size,code) in blocks:
    file.write(digest)
    Format.write_int(file,size)
    Format.write_int(file,code)