Ejemplo n.º 1
0
    def restore_image(self):
        """ """
        information = Information(self.image_path)
        information.load()
        image_name = information.get_image_name()
        compressor_level = information.get_image_compressor_level()
        total_bytes = information.get_image_total_bytes()
        total_blocks = long(math.ceil(total_bytes/float(BLOCK_SIZE)))

        device = Device(self.target_device)

        if device.is_disk() != \
           information.get_image_is_disk():
            raise ErrorRestoringImage("Invalid target dispositive")

        try:
            disk = Disk(device)
        except _ped.DiskLabelException:
            try:
                device.fix_disk_label()
                disk = Disk(device)
            except:
                raise ErrorRestoringImage("Unrecognized disk label")

        if information.get_image_is_disk():
            mbr = Mbr(self.image_path)
            mbr.restore_from_file(self.target_device)
            dlm = DiskLayoutManager(self.image_path)
            dlm.restore_from_file(disk)

        self._print_informations(total_bytes, image_name)
        progress = Progress(total_blocks)
        progress.start()
        partitions = information.get_partitions()
        for part in partitions:
            if information.get_image_is_disk():
                partition = disk.get_partition_by_number(part.number, part.type)
            else:
                parent_path = get_parent_path(self.target_device)
                parent_device = Device(parent_path)
                parent_disk = Disk(parent_device)
                partition = parent_disk.get_partition_by_path(
                                            self.target_device,
                                            part.type)

            if partition is None:
                raise ErrorRestoringImage("No valid partitions found")

            if hasattr(part, "uuid"):
                partition.filesystem.open_to_write(part.uuid)
            else:
                partition.filesystem.open_to_write()

            if partition.filesystem.is_swap():
                continue

            current_volume = 1
            while True:
                file_name = FILE_PATTERN % (image_name, part.number, current_volume)
                file_path = self.image_path + file_name

                reader = ReaderFactory(file_path, compressor_level)

                for data in reader:
                    partition.filesystem.write(data)
                    progress.increment(1)

                if hasattr(part, "volumes"):
                    if current_volume < part.volumes:
                        current_volume += 1
                        continue
                break
            partition.filesystem.close()

        progress.stop()
        print "completed."
Ejemplo n.º 2
0
    def restore_image(self):
        """ """
        information = Information(self.image_path)
        information.load()
        image_name = information.get_image_name()
        compressor_level = information.get_image_compressor_level()
        total_bytes = information.get_image_total_bytes()
        total_blocks = long(math.ceil(total_bytes / float(BLOCK_SIZE)))

        compressor = Compressor(compressor_level)

        device = Device(self.target_device)

        if device.is_disk() != \
           information.get_image_is_disk():
            raise ErrorRestoringImage("Invalid target dispositive")

        try:
            disk = Disk(device)
        except _ped.DiskLabelException:
            try:
                device.fix_disk_label()
                disk = Disk(device)
            except:
                raise ErrorRestoringImage("Unrecognized disk label")

        if information.get_image_is_disk():
            mbr = Mbr(self.image_path)
            mbr.restore_from_file(self.target_device)
            dlm = DiskLayoutManager(self.image_path)
            dlm.restore_from_file(disk)

        self._print_informations(total_bytes, image_name)
        progress = Progress(total_blocks)
        progress.start()
        partitions = information.get_partitions()
        for p in partitions:
            if information.get_image_is_disk():
                partition = disk.get_partition_by_number(p.number, p.type)
            else:
                parent_path = get_parent_path(self.target_device)
                parent_device = Device(parent_path)
                parent_disk = Disk(parent_device)
                partition = parent_disk.get_partition_by_path(
                    self.target_device, p.type)

            if partition is None:
                raise ErrorRestoringImage("No valid partitions found")

            if p.uuid is not None:
                partition.filesystem.open_to_write(p.uuid)
            else:
                partition.filesystem.open_to_write()

            if partition.filesystem.is_swap():
                continue

            file_name = FILE_PATTERN % (image_name, p.number)
            with open(self.image_path + file_name, 'rb') as f:
                # TODO: Work with parallelism
                while True:  # Ugly
                    header = f.read(compressor.get_header_size())
                    if not len(header):
                        break
                    size = compressor.read_block_header(header)
                    cdata = f.read(size)
                    data = compressor.extract(cdata)
                    partition.filesystem.write(data)
                    progress.increment(1)
            partition.filesystem.close()

        progress.stop()
        print "completed."
Ejemplo n.º 3
0
    def restore_image(self):
        """ """
        information = Information(self.image_path)
        information.load()
        image_name = information.get_image_name()
        compressor_level = information.get_image_compressor_level()
        total_bytes = information.get_image_total_bytes()
        total_blocks = long(math.ceil(total_bytes/float(BLOCK_SIZE)))

        compressor = Compressor(compressor_level)

        device = Device(self.target_device)

        if device.is_disk() != \
           information.get_image_is_disk():
            raise ErrorRestoringImage("Invalid target dispositive")

        try:
            disk = Disk(device)
        except _ped.DiskLabelException:
            try:
                device.fix_disk_label()
                disk = Disk(device)
            except:
                raise ErrorRestoringImage("Unrecognized disk label")

        if information.get_image_is_disk():
            mbr = Mbr(self.image_path)
            mbr.restore_from_file(self.target_device)
            dlm = DiskLayoutManager(self.image_path)
            dlm.restore_from_file(disk)

        self._print_informations(total_bytes, image_name)
        progress = Progress(total_blocks)
        progress.start()
        partitions = information.get_partitions()
        for p in partitions:
            if information.get_image_is_disk():
                partition = disk.get_partition_by_number(p.number, p.type)
            else:
                parent_path = get_parent_path(self.target_device)
                parent_device = Device(parent_path)
                parent_disk = Disk(parent_device)
                partition = parent_disk.get_partition_by_path(
                                            self.target_device,
                                            p.type)

            if partition is None:
                raise ErrorRestoringImage("No valid partitions found")

            if p.uuid is not None:
                partition.filesystem.open_to_write(p.uuid)
            else:
                partition.filesystem.open_to_write()

            if partition.filesystem.is_swap():
                continue

            file_name = FILE_PATTERN % (image_name, p.number)
            with open(self.image_path + file_name, 'rb') as f:
                # TODO: Work with parallelism
                while True: # Ugly
                    header = f.read(compressor.get_header_size())
                    if not len(header):
                        break
                    size = compressor.read_block_header(header)
                    cdata = f.read(size)
                    data = compressor.extract(cdata)
                    partition.filesystem.write(data)
                    progress.increment(1)
            partition.filesystem.close()

        progress.stop()
        print "completed."