RawImageCreator: do not use double with statement
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Mon, 29 Oct 2012 13:34:47 +0000 (15:34 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Mon, 5 Nov 2012 13:08:35 +0000 (15:08 +0200)
Double with statements are only supported starting from python-2.7, while
mic is 2.5-compatible. Turn the double with statement in the bmap generation
code to 2 single with statements.

Change-Id: I2ce186b4a9be8b7746c88bb96c98f4af470fa7d8
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
mic/imager/raw.py

index 205c7c2..b4d06a9 100644 (file)
@@ -596,28 +596,31 @@ class RawImageCreator(BaseImageCreator):
 
             image_size = os.path.getsize(image)
 
-            with open(bmap_file, "w") as f_bmap, open(image, "rb") as f_image:
-                # Get the block size of the host file-system for the image file
-                # by calling the FIGETBSZ ioctl (number 2).
-                block_size = unpack('I', ioctl(f_image, 2, pack('I', 0)))[0]
-                blocks_cnt = (image_size + block_size - 1) / block_size
-
-                # Write general information to the block map file, without
-                # block map itself, which will be written next.
-                xml = self._bmap_file_start(block_size, image_size, blocks_cnt)
-                f_bmap.write(xml)
-
-                # Generate the block map and write it to the XML block map file
-                # as we go.
-                mapped_cnt = 0
-                for first, last in self._get_ranges(f_image, blocks_cnt):
-                    mapped_cnt += last - first + 1
-                    sha1 = misc.calc_hashes(image, ('sha1', ),
-                                            first * block_size,
-                                            (last + 1) * block_size)
-                    f_bmap.write("\t\t<Range sha1=\"%s\"> %s-%s </Range>\n" \
-                            % (sha1[0], first, last))
-
-                # Finish the block map file
-                xml = self._bmap_file_end(mapped_cnt, block_size, blocks_cnt)
-                f_bmap.write(xml)
+            with open(bmap_file, "w") as f_bmap:
+                with open(image, "rb") as f_image:
+                    # Get the block size of the host file-system for the image
+                    # file by calling the FIGETBSZ ioctl (number 2).
+                    block_size = unpack('I', ioctl(f_image, 2, pack('I', 0)))[0]
+                    blocks_cnt = (image_size + block_size - 1) / block_size
+
+                    # Write general information to the block map file, without
+                    # block map itself, which will be written next.
+                    xml = self._bmap_file_start(block_size, image_size,
+                                                blocks_cnt)
+                    f_bmap.write(xml)
+
+                    # Generate the block map and write it to the XML block map
+                    # file as we go.
+                    mapped_cnt = 0
+                    for first, last in self._get_ranges(f_image, blocks_cnt):
+                        mapped_cnt += last - first + 1
+                        sha1 = misc.calc_hashes(image, ('sha1', ),
+                                                first * block_size,
+                                                (last + 1) * block_size)
+                        f_bmap.write("\t\t<Range sha1=\"%s\"> %s-%s " \
+                                     "</Range>\n" % (sha1[0], first, last))
+
+                    # Finish the block map file
+                    xml = self._bmap_file_end(mapped_cnt, block_size,
+                                              blocks_cnt)
+                    f_bmap.write(xml)