From 4d8235f567e577063abe554d10a7a6cae0cb7293 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 27 Jul 2011 17:34:50 +0400 Subject: [PATCH] Change output sizePartition. --- pym/cl_utils.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pym/cl_utils.py b/pym/cl_utils.py index 0ffc201..f477aea 100644 --- a/pym/cl_utils.py +++ b/pym/cl_utils.py @@ -1154,18 +1154,24 @@ def getPartitionSize(dev): SECTORSIZE=512 sizeFile = pathJoin(dev,"size") if path.exists(sizeFile): - size = float(open(sizeFile,'r').read().strip())*SECTORSIZE - suffix = ((1024**0,""), - (1024**1,"KiB"), - (1024**2,"MiB"), - (1024**3,"GiB"), - (1024**4,"TiB"), - (1024**5,"PiB")) - suffix = filter(lambda x:size >=x[0],suffix) + size = int(open(sizeFile,'r').read().strip())*SECTORSIZE + suffix = (((1024**0),"",False), + ((1024**1),"K",False), + ((1024**2),"M",False), + ((1024**3),"G",True), + ((1024**4),"T",True), + ((1024**5),"P",True)) + suffix = filter(lambda x:size >x[0],suffix) if suffix: suffix = suffix[-1] - return "%.1f %s"%(size/suffix[0],suffix[1]) - return "0" + printSize = size / (suffix[0]/10) + printSizeTail = printSize % 10 + printSize = printSize / 10 + if suffix[2] and printSizeTail: + return "%d.%d%s"%(printSize,printSizeTail,suffix[1]) + else: + return "%d%s"%(printSize,suffix[1]) + return "" def getDeviceType(syspath): """Get device type (disk,partition,lvm,raid)"""