BmapHelpers: handle small sizes correctly
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 1 Nov 2012 14:25:11 +0000 (16:25 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 1 Nov 2012 14:25:11 +0000 (16:25 +0200)
Make sure we provide sane human-readable size for small sizes like 1 byte or 10
bytes. With this change, for sizes less than 512 we'll print X bytes, while for
larger sized we'll print 0.YKiB.

Change-Id: I7a5a32ed3a9dc26fb754299c55d7dbffdf531a37
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptools/BmapHelpers.py

index 605d421..64f7361 100644 (file)
@@ -6,6 +6,12 @@ BmapFlasher and BmapCreator or which are useful for users of bmaptools.
 def human_size(size):
     """ Transform size in bytes into a human-readable form. """
 
+    if size == 1:
+        return "1 byte"
+
+    if size < 512:
+        return "%d bytes" % size
+
     for modifier in ["KiB", "MiB", "GiB", "TiB"]:
         size /= 1024.0
         if size < 1024: