File: list_partitions.py

package info (click to toggle)
pyparted 3.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 952 kB
  • sloc: ansic: 7,453; python: 4,579; makefile: 91; sh: 4
file content (21 lines) | stat: -rw-r--r-- 601 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python3
# 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)