2012-05-20 18:09:51 +02:00
|
|
|
#!/usr/bin/python2 -B
|
2012-05-20 17:51:55 +02:00
|
|
|
|
|
|
|
""" simple display to show results of disk.py """
|
|
|
|
|
|
|
|
import disk
|
|
|
|
|
2012-05-20 19:19:28 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2012-05-20 17:51:55 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
diskmoninstance = disk.diskmon()
|
|
|
|
for partition in diskmoninstance.partitions:
|
2012-05-21 00:08:07 +02:00
|
|
|
print "Device:\t\t" + str(partition["device"])
|
|
|
|
print "UUID:\t\t" + str(partition["uuid"])
|
2012-05-20 17:51:55 +02:00
|
|
|
if partition.has_key("mountpoint"):
|
2012-05-20 19:19:28 +02:00
|
|
|
totalbytes = blocks2bytes(partition["total blocks"], partition["blocksize"])
|
|
|
|
totalhuman = bytes2human(totalbytes)
|
2012-05-20 23:11:40 +02:00
|
|
|
freebytes = blocks2bytes(partition["free blocks"], partition["blocksize"])
|
|
|
|
freehuman = bytes2human(freebytes)
|
2012-05-20 19:19:28 +02:00
|
|
|
print "Mountpoint:\t" + str(partition["mountpoint"]) + \
|
|
|
|
"\nFilesystem:\t" + str(partition["filesystem"]) + \
|
2012-05-21 00:08:07 +02:00
|
|
|
"\nUsage:\t\t%.2f%s/%.2f%s\n" %(freehuman[0], freehuman[1], totalhuman[0], totalhuman[1])
|
2012-05-20 17:51:55 +02:00
|
|
|
else:
|
|
|
|
print "\n"
|
2012-05-20 18:09:51 +02:00
|
|
|
|
|
|
|
#end of file
|