BmapCopy: verify versions in a single function
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 1 Nov 2013 10:38:58 +0000 (12:38 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 1 Nov 2013 11:18:46 +0000 (13:18 +0200)
This patch is a minor clean-up and a preparation to the upcoming changes. It
makes sure that all the differences between various bmap format version are
handled in the '_parse_bmap()' method, and we do not have to worry about the
format differences later on.

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

index fe8897c552e4a60318baf66312b4abe3470a6e45..357b45d620b8033da452df5a4eb2243050efd349 100644 (file)
@@ -176,6 +176,7 @@ class BmapCopy:
         self._cs_type = None
         self._cs_len = None
         self._cs_attrib_name = None
+        self._bmap_cs_attrib_name = None
 
         # Special quirk for /dev/null which does not support fsync()
         if stat.S_ISCHR(st_data.st_mode) and \
@@ -247,10 +248,7 @@ class BmapCopy:
 
         import mmap
 
-        if self.bmap_version_minor == 3:
-            correct_chksum = self._xml.find("BmapFileSHA1").text.strip()
-        else:
-            correct_chksum = self._xml.find("BmapFileChecksum").text.strip()
+        correct_chksum = self._xml.find(self._bmap_cs_attrib_name).text.strip()
 
         # Before verifying the shecksum, we have to substitute the checksum
         # value stored in the file with all zeroes. For these purposes we
@@ -329,9 +327,11 @@ class BmapCopy:
             if self.bmap_version_minor == 3:
                 self._cs_type = "sha1"
                 self._cs_attrib_name = "sha1"
+                self._bmap_cs_attrib_name = "BmapFileSHA1"
             else:
                 self._cs_type = xml.find("ChecksumType").text.strip()
                 self._cs_attrib_name = "chksum"
+                self._bmap_cs_attrib_name = "BmapFileChecksum"
 
             try:
                 self._cs_len = len(hashlib.new(self._cs_type).hexdigest())