Package: python-parted
Severity: wishlist

hi,

searching the web for examples on how to use python-parted was not quite
successful, i think the only good resource at the moment is to look at the
anaconda sourcecode. Maybe its possible to provide some simple examples to get
one started. Attached are two small examples, one which shows simple
information about attached devices, another one which lists partitions for a
certain device.

bye,
    - michael
#!/usr/bin/python
# simple example on how to list available devices on system
import parted

devices = parted.getAllDevices();

for device in devices:
    geom = device.hardwareGeometry;
    ssize = device.sectorSize;
    size = (geom[0] * geom[1] * geom[2] * ssize) / 1000 / 1000 / 1000;

    print "Model: %s" %   device.model
    print "Size: %s GB" %  size 
    print "Heads: %s" %  geom[0]
    print "Sectors: %s" %  geom[2]
    print "Sector Size: %s" % ssize; 
#!/usr/bin/python
# list primary partitions for a given device
import parted

device = parted.getDevice("/dev/sda")
disk = parted.Disk(device)


# obj.getLogicalPartitions() for logical
# obj.getExtendedPartition() for extended
primary_partitions = disk.getPrimaryPartitions();

for partition in primary_partitions:
	print "Partition: %s" % partition.path
	print "Size: %s Bytes" % partition.getSize(unit="b")
	try:
		fs = parted.probeFileSystem(partition.geometry)
	except:
		fs = "unknown"
	print "Filesystem: %s" % fs
	print "Start: %s End: %s" % (partition.geometry.start,partition.geometry.end)

Reply via email to