trying to get a nice disk display working
This commit is contained in:
parent
c7f8e97302
commit
4e3aee7738
|
@ -4,17 +4,31 @@
|
||||||
|
|
||||||
import disk
|
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__":
|
if __name__ == "__main__":
|
||||||
diskmoninstance = disk.diskmon()
|
diskmoninstance = disk.diskmon()
|
||||||
for partition in diskmoninstance.partitions:
|
for partition in diskmoninstance.partitions:
|
||||||
print "device\t\t:" + str(partition["device"]) + \
|
print "Device:\t\t" + str(partition["device"]) + \
|
||||||
"\nuuid\t\t:" + str(partition["uuid"])
|
"\nUUID:\t\t" + str(partition["uuid"])
|
||||||
if partition.has_key("mountpoint"):
|
if partition.has_key("mountpoint"):
|
||||||
print "mountpoint:\t" + str(partition["mountpoint"]) + \
|
totalbytes = blocks2bytes(partition["total blocks"], partition["blocksize"])
|
||||||
"\nfilesystem:\t" + str(partition["filesystem"]) + \
|
totalhuman = bytes2human(totalbytes)
|
||||||
"\nblocksize:\t" + str(partition["blocksize"]) + \
|
print "Mountpoint:\t" + str(partition["mountpoint"]) + \
|
||||||
"\ntotal blocks:\t" + str(partition["total blocks"]) + \
|
"\nFilesystem:\t" + str(partition["filesystem"]) + \
|
||||||
"\nfree blocks:\t" + str(partition["free blocks"]) + "\n"
|
"\nSize:\t\t%.2f %s\n" %(totalhuman[0], totalhuman[1])
|
||||||
else:
|
else:
|
||||||
print "\n"
|
print "\n"
|
||||||
|
|
||||||
|
|
Reference in New Issue