recently I just started to use python3 and realised that there alot of changes made from python2.6. I want to know is there anyway to format the view of the hard disks available in a linux system by using fdisk? in python2.6, it worked something like this;
def parse_fdisk(fdisk_output):
result = {}
for line in fdisk_output.split("\n"):
if not line.startswith("/"): continue
parts = line.split()
inf = {}
if parts[1] == "*":
inf['bootable'] = True
del parts[1]
else:
inf['bootable'] = False
inf['start'] = int(parts[1])
inf['end'] = int(parts[2])
inf['blocks'] = int(parts[3].rstrip("+"))
inf['partition_id'] = int(parts[4], 16)
inf['partition_id_string'] = " ".join(parts[5:])
result[parts[0]] = inf
return result
def main():
fdisk_output = commands.getoutput("fdisk -l")
for disk, info in parse_fdisk(fdisk_output).items():
print disk, " ".join(["%s=%r" % i for i in info.items()])