Device class is used as a wrapper to libparted’s ped_device.
You need to call this class before calling Disk. You can create a new instance of Device by specifying a path or let it probe standard devices:
from reparted import *
# specify the device path
myDevice = Device("/dev/sdb")
# probe standard devices
myDevice2 = Device()
Args:
Raises:
Note
If called without any parameters it will probe all standard devices and default to the first one it finds.
Returns the bios geometry as a 3-tuple:
(cylinders, heads, sectors)
Returns True if the device is set to boot dirty.
Returns the device did.
Returns True if the device is dirty.
Returns True if the device is set to external mode.
Returns the device host.
Returns the hardware geometry as a 3-tuple:
(cylinders, heads, sectors)
Returns the length in sectors of the device.
Returns the device model (ie. ‘ATA VBOX HARDDISK’).
Returns the number of times the device has been opened.
Returns the device path (ie. ‘/dev/sda’).
Returns the physical sector size.
Returns True if the device is set as read only.
Returns the size as a Size class instance.
Returns the device type (ie. ‘SCSI’).
This function probes all standard devices and returns a list containing instances of Device of the found standard devices:
from reparted.device import probe_standard_devices
probe_standard_devices()
[<reparted.device.Device object at 0xb7854d8c>,
<reparted.device.Device object at 0xb7607eac>]
Size class is used as a container to specify desired partition sizes.
You need to call this class before adding Partition instances. The default values for units is “MB” and sector_size is set to 512. You can manually specify the sector size or pass the device you intend to use it with and have it obtain the sector size from there:
from reparted import *
# sector size defaults to 512
mySize1 = Size(4, "GB")
# manually set the sector size to 1024
mySize2 = Size(4, "GB", sector_size=1024)
# get the sector size from the device
myDevice = Device('/dev/sda')
mySize = Size(4, "GB", dev=myDevice)
There is an option to choose percentage ‘%’ as units, in which case you need to pass a Device instance to calculate the sectors needed and length should be between 1 and 100:
from reparted import *
myDevice = Device('/dev/sda')
mySize = Size(25, "%", dev=myDevice)
Since version 1.2, the Size class supports basic operations:
myDevice = Device('/dev/sda')
mySize = Size(25, "%", dev=myDevice)
otherSize = Size(4, "GB")
newSize = (otherSize - mySize) + size(50, "MB")
if newSize > Size(3, "GB"):
print "YAY!"
Supported operations are + - += -= < <= >= > == !=.
Args:
Raises:
Note
When using percent as unit and using the Size instance for multiple disks make sure they all have the same sector size.
Returns the size in the specified units in a pretty string.
Args:
Returns the size in the specified units.
Args:
Disk class is used as a wrapper to libparted’s ped_disk.
You need to call this class to list, add or delete partitions. A new instance of Disk is initialized by passing the Device instance:
from reparted import *
myDevice = Device("/dev/sda")
myDisk = Disk(myDevice)
Args:
Raises:
Note
You need to pass either a Device instance or a ped_disk pointer. If a disk is being initialized (no partition table) only the set_label method is available, with other methods returning None or raising DiskError.
Adds a partition to disk. You still need to call commit for the changes to be made to disk:
from reparted import *
myDevice = Device("/dev/sdb")
myDisk = Disk(myDevice)
mySize = Size(4, "GB")
myPartition = Partition(myDisk, mySize)
myDisk.add_partition(myPartition)
myDisk.commit()
Args:
Raises:
Note
If the disk is initialized (no partition table) it will raise DiskError.
Returns the disk block sizes.
This method commits partition modifications to disk.
Raises:
Note
If the disk is initialized (no partition table) it will return None.
This method deletes all partitions from disk.
Raises:
Note
If the disk is initialized (no partition table) it will return None.
Deletes a partition from disk. Unlike add_partition, this method calls commit, use carefully:
from reparted import *
myDevice = Device("/dev/sdb")
myDisk = Disk(myDevice)
# Get Partition instance and remove it.
part = myDisk.partitions()[0]
myDisk.delete_partition(part)
# Get Partition number and remove it.
part = myDisk.partitions()[0].num
myDisk.delete_partition(part)
Args:
Raises:
Note
If the disk is initialized (no partition table) it will raise DiskError.
Returns the Device the disk belongs to.
Returns a list of the current free space allocations as Partition instances.
Note
If the disk is initialized (no partition table) it will return None.
Returns a Partition instance.
Args:
Raises:
Note
If the disk is initialized (no partition table) it will raise DiskError.
Returns True if the disk needs clobber.
Returns a list of the current disk partitions.
Note
If the disk is initialized (no partition table) it will return None, if the disk has a partition table but no partitions it will return an empty list.
Sets the disk partition table (‘gpt’ or ‘msdos)’. This method calls commit to set the label changes.
Args:
Raises:
Returns the size as a Size class instance.
Returns the total free space size as a Size class instance.
Returns the features available (ie. ‘EXTENDED’ for lvm and ‘PARTITION_NAME’ for label support).
Returns the disk type (ie. ‘gpt’ or ‘msdos’).
Returns True if the disk is set to update mode.
Returns the largest free space size as a Size class instance.
Wraps disk methods to check if the instance of Disk points to a initialized disk.
Partition class is used as a wrapper to libparted’s ped_partition.
You need can create Partition instances and add them to disk. A new Partition instance can be initialized:
from reparted import *
myDevice = Device("/dev/sda")
myDisk = Disk(myDevice)
mySize = Size(4, "GB")
# Defaults
myPartition = Partition(myDisk, mySize)
# Different filesystem and minimal alignment.
myPartition = Partition(myDisk, mySize, fs="ext4", align="minimal")
# Initialize with a name
if myDisk.type_features == 'PARTITION_NAME':
myPartition = Partition(myDisk, mySize, name="test")
Args:
Raises:
Note
Name is only available when partition type is ‘NORMAL’. The start and end arguments are optional and you should only use them when your want to specify such attributes, otherwise use optimal alignment. The part argument is optional and mostly for internal use.
Returns the partition alignment (‘optimal’ or ‘minimal’).
Note
If you specify a ‘minimal’ alignment when creating a partition but the start sector falls in what would be considered an optimal alignment this method will return ‘optimal’.
Returns the Device instance this partition belongs to.
Returns the Disk instance this partition belongs to.
Returns the partition filesystem type.
Returns the partition geometry as a 3-tuple:
(start, end, length)
Returns the partition name if names are supported by disk type, otherwise returns None.
Returns the partition number. If the partition is of type ‘FREESPACE’ it will return -1.
Sets the partition flag (ie. ‘BOOT’, ‘ROOT’, etc...).
Args:
Sets the partition name. If the disk type does not support partition names it will raise NotImplementedError.
Args:
Raises:
Returns the size as a Size class instance.
Returns the partition type.
Raised when the Disk add_partition method fails for the following reasons:
Raised when the Disk delete_partition method fails for the following reasons:
Raised when a Device class error occurs for the following reasons:
Raised when the Disk commit method fails for the following reasons:
Raised when a Disk class error occurs for the following reasons:
Raised when a Partition class error occurs for the following reasons:
Raised when a Size class error occurs for the following reasons: