import stat
import time
import logging
-from bmaptools import BmapFlasher
+from bmaptools import BmapFlasher, BmapHelpers
def parse_arguments():
""" A helper function which parses the input arguments. """
return parser.parse_args()
-def human_size(size):
- """ Transform size in bytes into a human-readable form. """
-
- for modifier in ["KiB", "MiB", "GiB", "TiB"]:
- size /= 1024.0
- if size < 1024:
- return "%.1f %s" % (size, modifier)
-
- return "%.1f %s" % (size, 'EiB')
-
-def human_time(seconds):
- """ Transform time in seconds to the HH:MM:SS format. """
-
- (minutes, seconds) = divmod(seconds, 60)
- (hours, minutes) = divmod(minutes, 60)
-
- result = ""
- if hours:
- result = "%dh " % hours
- if minutes:
- result += "%dm " % minutes
-
- return result + "%.1fs" % seconds
-
def setup_logger(loglevel):
""" A helper function which sets up and configures the logger. The log
level is initialized to 'loglevel'. Returns the logger object. """
log.info("block map format version %s" % flasher.bmap_version)
log.info("%d blocks of size %d (%s), mapped %d blocks (%s or %.1f%%)" \
% (flasher.bmap_blocks_cnt, flasher.bmap_block_size,
- human_size(flasher.bmap_total_size),
+ BmapHelpers.human_size(flasher.bmap_total_size),
flasher.bmap_mapped_cnt,
- human_size(flasher.bmap_mapped_size),
+ BmapHelpers.human_size(flasher.bmap_mapped_size),
flasher.bmap_mapped_percent))
log.info("writing the image to '%s' using bmap file '%s'" \
% (args.bdev, args.bmap))
flashing_time = time.time() - start_time
flashing_speed = flasher.bmap_total_size / flashing_time
log.info("flashing time: %s, flashing speed %s/sec" \
- % (human_time(flashing_time), human_size(flashing_speed)))
+ % (BmapHelpers.human_time(flashing_time), \
+ BmapHelpers.human_size(flashing_speed)))
if __name__ == "__main__":
sys.exit(main())
--- /dev/null
+"""
+This module contains various helper functions which are shared between
+BmapFlasher and BmapCreator or which are useful for users of bmaptools.
+"""
+
+def human_size(size):
+ """ Transform size in bytes into a human-readable form. """
+
+ for modifier in ["KiB", "MiB", "GiB", "TiB"]:
+ size /= 1024.0
+ if size < 1024:
+ return "%.1f %s" % (size, modifier)
+
+ return "%.1f %s" % (size, 'EiB')
+
+def human_time(seconds):
+ """ Transform time in seconds to the HH:MM:SS format. """
+
+ (minutes, seconds) = divmod(seconds, 60)
+ (hours, minutes) = divmod(minutes, 60)
+
+ result = ""
+ if hours:
+ result = "%dh " % hours
+ if minutes:
+ result += "%dm " % minutes
+
+ return result + "%.1fs" % seconds