Welcome to reparted’s documentation! — reparted 1.2 documentation

### Navigation

- index
- modules |
- next |
- reparted 1.2 documentation »

# Welcome to reparted’s documentation!

Contents:

- Quickstart

# Indices and tables

- Index
- Module Index
- Search Page

class `device.` `Device`(path=None, dev=None)

  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:

  - path (str): Path to your local device of choice (ie. ‘/dev/sda’).
  - dev: A ped_device pointer, usually this is used internally.

  Raises:

  - DeviceError

  Note

  If called without any parameters it will probe all standard devices and default to the first one it finds.

  `bios_geom`

    Returns the bios geometry as a 3-tuple:

    > (cylinders, heads, sectors)

  `boot_dirty`

    Returns True if the device is set to boot dirty.

  `did`

    Returns the device did.

  `dirty`

    Returns True if the device is dirty.

  `external_mode`

    Returns True if the device is set to external mode.

  `host`

    Returns the device host.

  `hw_geom`

    Returns the hardware geometry as a 3-tuple:

    > (cylinders, heads, sectors)

  `length`

    Returns the length in sectors of the device.

  `model`

    Returns the device model (ie. ‘ATA VBOX HARDDISK’).

  `open_count`

    Returns the number of times the device has been opened.

  `path`

    Returns the device path (ie. ‘/dev/sda’).

  `phys_sector_size`

    Returns the physical sector size.

  `read_only`

    Returns True if the device is set as read only.

  `size`

    Returns the size as a Size class instance.

  `type`

    Returns the device type (ie. ‘SCSI’).

`device.` `probe_standard_devices`()

  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>]

class `size.` `Size`(length=0, units='MB', sector_size=512, dev=None)

  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:

  - length (int): The desired length.
  - units (str): The desired units (ie. “MB”, “GB”, “%” etc...)
  - sector_size (int): The sector size to be used to calculate.
  - dev: A Device instance. Only needed when using percents, otherwise calculations will take sector size from Device.sector_size.

  Raises:

  - SizeError

  Note

  When using percent as unit and using the Size instance for multiple disks make sure they all have the same sector size.

  `pretty`(units='MB')

    Returns the size in the specified units in a pretty string.

    Args:

    - units (str): The desired units (ie. “MB”, “GB”, “%” etc...)
  `to`(units='MB')

    Returns the size in the specified units.

    Args:

    - units (str): The desired units (ie. “MB”, “GB”, “%” etc...)

class `disk.` `Disk`(device, disk=None)

  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:

  - dev: A Device class instance.
  - disk: A ped_disk pointer, usually this is used internally.

  Raises:

  - DiskError

  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.

  `add_partition`(*args, **kwargs)

    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:

    - part: A Partition class instance.

    Raises:

    - AddPartitionError

    Note

    If the disk is initialized (no partition table) it will raise DiskError.

  `block_sizes`

    Returns the disk block sizes.

  `commit`(*args, **kwargs)

    This method commits partition modifications to disk.

    Raises:

    - DiskError, DiskCommitError

    Note

    If the disk is initialized (no partition table) it will return None.

  `delete_all`(*args, **kwargs)

    This method deletes all partitions from disk.

    Raises:

    - DiskError, DiskCommitError

    Note

    If the disk is initialized (no partition table) it will return None.

  `delete_partition`(*args, **kwargs)

    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:

    - part: A Partition class instance OR partition number.

    Raises:

    - DeletePartitionError, DiskCommitError

    Note

    If the disk is initialized (no partition table) it will raise DiskError.

  `device`

    Returns the Device the disk belongs to.

  `free_partitions`(*args, **kwargs)

    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.

  `get_partition`(*args, **kwargs)

    Returns a Partition instance.

    Args:

    - part_num (int): A partition number.

    Raises:

    - PartitionError

    Note

    If the disk is initialized (no partition table) it will raise DiskError.

  `needs_clobber`

    Returns True if the disk needs clobber.

  `partitions`(*args, **kwargs)

    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.

  `set_label`(label)

    Sets the disk partition table (‘gpt’ or ‘msdos)’. This method calls commit to set the label changes.

    Args:

    - label (str): A partition table type (‘gpt’ or ‘msdos’)

    Raises:

    - DiskError
  `size`

    Returns the size as a Size class instance.

  `total_free_space`

    Returns the total free space size as a Size class instance.

  `type_features`

    Returns the features available (ie. ‘EXTENDED’ for lvm and ‘PARTITION_NAME’ for label support).

  `type_name`

    Returns the disk type (ie. ‘gpt’ or ‘msdos’).

  `update_mode`

    Returns True if the disk is set to update mode.

  `usable_free_space`

    Returns the largest free space size as a Size class instance.

`disk.` `diskDecorator`(error=False)

  Wraps disk methods to check if the instance of Disk points to a initialized disk.

exception `exception.` `AddPartitionError`(code)

  Raised when the Disk add_partition method fails for the following reasons:

  - Failed to add partition to disk.
  - Failed to set user-defined constraint to disk.
  - Failed to set device constraint to disk.
  - Failed to set partition name to disk.

exception `exception.` `DeletePartitionError`(code)

  Raised when the Disk delete_partition method fails for the following reasons:

  - Invalid partition instance or partition number.
  - Partition is busy.

exception `exception.` `DeviceError`(code)

  Raised when a Device class error occurs for the following reasons:

  - No device found.

exception `exception.` `DiskCommitError`(code)

  Raised when the Disk commit method fails for the following reasons:

  - Failed to commit to device.
  - Failed to commit to OS.

exception `exception.` `DiskError`(code)

  Raised when a Disk class error occurs for the following reasons:

  - Failed to initialize disk.
  - Unsupported disk label.
  - Failed to get disk type.
  - Failed to create new disk.
  - Method unavailable for initialized disk.

exception `exception.` `PartitionError`(code)

  Raised when a Partition class error occurs for the following reasons:

  - Failed to initialize partition.
  - Failed to set partition name to disk.
  - Invalid partition instance or partition number.
  - Invalid partition type.
  - Invalid alignment option.
  - Invalid geometry.
  - Unsupported flag.

exception `exception.` `SizeError`(code)

  Raised when a Size class error occurs for the following reasons:

  - Device instance required for this operation.
  - Invalid length type.

### Navigation

- index
- modules |
- next |
- reparted 1.2 documentation »