filesizeformat() does't consider the situation like float('inf')

Sometimes the `bytes` may get float('inf'), then it will display "inf0PB" which will be a
    misleading for the user. Besides, with the hardware like storage and MEM getting larger
    and larger, we should consider size larger than PB like EB, ZB and YB.

Change-Id: I830ad440e9ef854006298bd946ab8ecf9d75757a
Closes-Bug: 1657174
This commit is contained in:
liaozd 2017-01-18 00:20:04 +08:00
parent 196cd93a13
commit 9886be592f

View File

@ -51,6 +51,8 @@ def filesizeformat(bytes, filesize_number_format):
return ungettext_lazy("%(size)d Byte",
"%(size)d Bytes", 0) % {'size': 0}
if bytes == float('inf'):
return _('Infinity')
if bytes < units.Ki:
bytes = int(bytes)
return ungettext_lazy("%(size)d Byte",
@ -63,7 +65,13 @@ def filesizeformat(bytes, filesize_number_format):
return _("%s GB") % filesize_number_format(bytes / units.Gi)
if bytes < units.Pi:
return _("%s TB") % filesize_number_format(bytes / units.Ti)
return _("%s PB") % filesize_number_format(bytes / units.Pi)
if bytes < units.Ei:
return _("%s PB") % filesize_number_format(bytes / units.Pi)
if bytes < units.Zi:
return _("%s EB") % filesize_number_format(bytes / units.Ei)
if bytes < units.Yi:
return _("%s ZB") % filesize_number_format(bytes / units.Zi)
return _("%s YB") % filesize_number_format(bytes / units.Yi)
def float_cast_filesizeformat(value, multiplier=1, format=int_format):