We are going to modify BmapCreate to support bmap file checksum. And we'll have
to seek the bmap file. However, the problem is that bmaptool may feed
BmapCreate with stdout which is not seekable.
This patch changes bmaptool and makes it create a temporary file when the user
does not specify the output file, give it to BmapCreate, and then print the
contents of the file to stdout. We use the 'NamedTemporaryFile' python method
which automatically removes the file when the program crashes or is interrupted
with Ctrl-C.
Change-Id: I0ad16136111095b04cf3a0e9223c004b493c26de
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
import stat
import time
import logging
+import tempfile
import traceback
from bmaptools import BmapCreate, BmapCopy, BmapHelpers, TransRead
% (args.output, err))
raise SystemExit(1)
else:
- output = sys.stdout
+ try:
+ # Create a temporary file for the bmap
+ output = tempfile.TemporaryFile("w+")
+ except IOError as err:
+ log.error("cannot create a temporary file: %s" % err)
+ raise SystemExit(1)
try:
creator = BmapCreate.BmapCreate(args.image, output)
log.error(str(err))
raise SystemExit(1)
+ if not args.output:
+ output.seek(0)
+ sys.stdout.write(output.read())
+
if creator.mapped_cnt == creator.blocks_cnt:
log.warning("all %s are mapped, no holes in '%s'" \
% (creator.image_size_human, args.image))