##// END OF EJS Templates
util: create bytecount array just once...
Matt Mackall -
r16397:f0f7f3fa default
parent child Browse files
Show More
@@ -1167,10 +1167,7 b' def ellipsis(text, maxlength=400):'
1167 except (UnicodeDecodeError, UnicodeEncodeError):
1167 except (UnicodeDecodeError, UnicodeEncodeError):
1168 return _ellipsis(text, maxlength)[0]
1168 return _ellipsis(text, maxlength)[0]
1169
1169
1170 def bytecount(nbytes):
1170 _byteunits = (
1171 '''return byte count formatted as readable string, with units'''
1172
1173 units = (
1174 (100, 1 << 30, _('%.0f GB')),
1171 (100, 1 << 30, _('%.0f GB')),
1175 (10, 1 << 30, _('%.1f GB')),
1172 (10, 1 << 30, _('%.1f GB')),
1176 (1, 1 << 30, _('%.2f GB')),
1173 (1, 1 << 30, _('%.2f GB')),
@@ -1183,7 +1180,10 b' def bytecount(nbytes):'
1183 (1, 1, _('%.0f bytes')),
1180 (1, 1, _('%.0f bytes')),
1184 )
1181 )
1185
1182
1186 for multiplier, divisor, format in units:
1183 def bytecount(nbytes):
1184 '''return byte count formatted as readable string, with units'''
1185
1186 for multiplier, divisor, format in _byteunits:
1187 if nbytes >= divisor * multiplier:
1187 if nbytes >= divisor * multiplier:
1188 return format % (nbytes / float(divisor))
1188 return format % (nbytes / float(divisor))
1189 return units[-1][2] % nbytes
1189 return units[-1][2] % nbytes
General Comments 0
You need to be logged in to leave comments. Login now