socialnerds/hive
socialnerds
/
hive
Archived
1
0
Fork 0

trying to get a nice disk display working

This commit is contained in:
David 2012-05-20 19:19:28 +02:00
parent c7f8e97302
commit 4e3aee7738
1 changed files with 21 additions and 7 deletions

View File

@ -4,17 +4,31 @@
import disk
def bytes2human(bytes):
units = ["B", "KB", "MB", "GB", "TB", "PB", "EB"]
counter = 0
while bytes > 1024:
bytes = bytes / 1024
counter += 1
human = [bytes, units[counter]]
return human
def blocks2bytes(blocks, blocksize):
bytes = float(blocks) * float(blocksize)
return bytes
if __name__ == "__main__":
diskmoninstance = disk.diskmon()
for partition in diskmoninstance.partitions:
print "device\t\t:" + str(partition["device"]) + \
"\nuuid\t\t:" + str(partition["uuid"])
print "Device:\t\t" + str(partition["device"]) + \
"\nUUID:\t\t" + str(partition["uuid"])
if partition.has_key("mountpoint"):
print "mountpoint:\t" + str(partition["mountpoint"]) + \
"\nfilesystem:\t" + str(partition["filesystem"]) + \
"\nblocksize:\t" + str(partition["blocksize"]) + \
"\ntotal blocks:\t" + str(partition["total blocks"]) + \
"\nfree blocks:\t" + str(partition["free blocks"]) + "\n"
totalbytes = blocks2bytes(partition["total blocks"], partition["blocksize"])
totalhuman = bytes2human(totalbytes)
print "Mountpoint:\t" + str(partition["mountpoint"]) + \
"\nFilesystem:\t" + str(partition["filesystem"]) + \
"\nSize:\t\t%.2f %s\n" %(totalhuman[0], totalhuman[1])
else:
print "\n"