trying to get a nice disk display working
This commit is contained in:
parent
c7f8e97302
commit
4e3aee7738
|
@ -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"
|
||||
|
||||
|
|
Reference in New Issue