def testCopyFileSegment(self):
     """Test copying on a simple file segment."""
     a = os.path.join(self.tempdir, 'a.txt')
     osutils.WriteFile(a, '789')
     b = os.path.join(self.tempdir, 'b.txt')
     osutils.WriteFile(b, '0123')
     filelib.CopyFileSegment(a, 'r', 2, b, 'r+', in_seek=1)
     self.assertEqual(osutils.ReadFile(b), '8923')
Example #2
0
 def testCopyFileSegment(self):
     """Test copying on a simple file segment."""
     a = os.path.join(self.tempdir, 'a.txt')
     osutils.WriteFile(a, b'7\xee9', mode='wb')
     b = os.path.join(self.tempdir, 'b.txt')
     osutils.WriteFile(b, b'0123\xff', mode='wb')
     filelib.CopyFileSegment(a, 'rb', 2, b, 'r+b', in_seek=1)
     self.assertEqual(osutils.ReadFile(b, mode='rb'), b'\xee923\xff')
Example #3
0
def PatchKernel(image, kern_file):
    """Patches a kernel with vblock from a stateful partition.

  Args:
    image: The stateful partition image.
    kern_file: The kernel file.
  """

    with tempfile.NamedTemporaryFile(prefix='stateful') as state_out, \
         tempfile.NamedTemporaryFile(prefix='vmlinuz_hd.vblock') as vblock:
        ExtractPartition(image, constants.PART_STATE, state_out)
        cros_build_lib.run(
            ['e2cp', '%s:/vmlinuz_hd.vblock' % state_out, vblock])
        filelib.CopyFileSegment(vblock, 'r', os.path.getsize(vblock),
                                kern_file, 'r+')
Example #4
0
def ExtractPartition(filename, partition, out_part):
  """Extracts partition from an image file.

  Args:
    filename: The image file.
    partition: The partition name. e.g. ROOT or KERNEL.
    out_part: The output partition file.
  """
  parts = image_lib.GetImageDiskPartitionInfo(filename)
  part_info = [p for p in parts if p.name == partition][0]

  offset = int(part_info.start)
  length = int(part_info.size)

  filelib.CopyFileSegment(filename, 'rb', length, out_part, 'wb',
                          in_seek=offset)