959 else: |
959 else: |
960 _rcpath.append(p) |
960 _rcpath.append(p) |
961 else: |
961 else: |
962 _rcpath = os_rcpath() |
962 _rcpath = os_rcpath() |
963 return _rcpath |
963 return _rcpath |
|
964 |
|
965 def bytecount(nbytes): |
|
966 '''return byte count formatted as readable string, with units''' |
|
967 |
|
968 units = ( |
|
969 (100, 1<<30, _('%.0f GB')), |
|
970 (10, 1<<30, _('%.1f GB')), |
|
971 (1, 1<<30, _('%.2f GB')), |
|
972 (100, 1<<20, _('%.0f MB')), |
|
973 (10, 1<<20, _('%.1f MB')), |
|
974 (1, 1<<20, _('%.2f MB')), |
|
975 (100, 1<<10, _('%.0f KB')), |
|
976 (10, 1<<10, _('%.1f KB')), |
|
977 (1, 1<<10, _('%.2f KB')), |
|
978 (1, 1, _('%.0f bytes')), |
|
979 ) |
|
980 |
|
981 for multiplier, divisor, format in units: |
|
982 if nbytes >= divisor * multiplier: |
|
983 return format % (nbytes / float(divisor)) |
|
984 return units[-1][2] % nbytes |