Browse Source

Change output sizePartition.

develop 2.2.20
Mike Hiretsky 11 years ago
parent
commit
4d8235f567
  1. 26
      pym/cl_utils.py

26
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)"""

Loading…
Cancel
Save