File: list_partitions.py

package info (click to toggle)
pyparted 3.11.7-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 936 kB
  • sloc: ansic: 7,184; python: 3,697; makefile: 93; sh: 4
file content (21 lines) | stat: -rw-r--r-- 600 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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)