Ejemplo n.º 1
0
    def setPartitionGeometry(self, partition=None, constraint=None, start=None, end=None):
        """Sets the Geometry of the specified Partition using the given
           Constraint and start and end sectors.  Note that this method
           does not modify the partition contents, just the partition
           table."""
        if not partition or not constraint:
            raise parted.DiskException("no partition or constraint specified")

        if not start or not end:
            raise parted.DiskException("no start or end geometry specified")

        return self.__disk.set_partition_geom(partition.getPedPartition(),
                                              constraint.getPedConstraint(),
                                              start, end)
Ejemplo n.º 2
0
    def calculateMaxPartitionGeometry(self, partition=None, constraint=None):
        """Get the maximum Geometry the Partition can be grown to,
           subject to the given Constraint."""
        if not partition:
            raise parted.DiskException("no partition specified")

        if constraint:
            return parted.Geometry(PedGeometry=self.__disk.get_max_partition_geometry(partition.getPedPartition(), constraint.getPedConstraint()))
        else:
            return parted.Geometry(PedGeometry=self.__disk.get_max_partition_geometry(partition.getPedPartition()))
Ejemplo n.º 3
0
    def maximizePartition(self, partition=None, constraint=None):
        """Grow the Partition's Geometry to the maximum possible subject
           to Constraint."""
        if not partition:
            raise parted.DiskException("no partition specified")

        if constraint:
            return self.__disk.maximize_partition(partition.getPedPartition(),
                                                  constraint.getPedConstraint())
        else:
            return self.__disk.maximize_partition(partition.getPedPartition())
Ejemplo n.º 4
0
    def removePartition(self, partition=None):
        """Removes specified Partition from this Disk.  NOTE:  If the
           Partition is an extended partition, it must not contain any
           logical partitions.  Also note that the partition is not
           actually destroyed unless you use the deletePartition()
           method."""
        if not partition:
            raise parted.DiskException("no partition specified")

        if self.__disk.remove_partition(partition.getPedPartition()):
            self.partitions.invalidate()
            return True
        else:
            return False
Ejemplo n.º 5
0
    def addPartition(self, partition=None, constraint=None):
        """Add a new Partition to this Disk with the given Constraint."""
        if constraint:
            result = self.__disk.add_partition(partition.getPedPartition(),
                                               constraint.getPedConstraint())
        elif not partition:
            raise parted.DiskException("no partition or constraint specified")
        else:
            result = self.__disk.add_partition(partition.getPedPartition())

        if result:
            partition.geometry = parted.Geometry(PedGeometry=partition.getPedPartition().geom)
            self.partitions.invalidate()
            return True
        else:
            return False
Ejemplo n.º 6
0
    def __init__(self, device=None, PedDisk=None):
        """Create a new Disk object from the device and type specified.  The
           device is a Device object and type is a string matching a key in
           the diskType hash."""
        if PedDisk:
            self.__disk = PedDisk

            if device is None:
                self._device = parted.Device(PedDevice=self.__disk.dev)
            else:
                self._device = device
        elif device is None:
            raise parted.DiskException("no device specified")
        else:
            self.__disk = _ped.Disk(device.getPedDevice())
            self._device = device

        # pylint: disable=W0108
        self._partitions = CachedList(lambda : self.__getPartitions())