Blob Blame History Raw
From 0e70861c9f72fb2e06f9a121e6dac0e542ee1230 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Wed, 27 Jun 2018 13:45:09 -0700
Subject: [PATCH 82/86] Modify gpt-header-move and msdos-overlap to work with
 py2 or py3

Distributions are starting to remove python2 and only use python3.
Modify these test scripts so that they will work with either python 2.7
or python 3.X
---
 tests/gpt-header-move | 15 ++++++++-------
 tests/msdos-overlap   |  5 ++---
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/tests/gpt-header-move b/tests/gpt-header-move
index 05cdc65..3dda5cb 100755
--- a/tests/gpt-header-move
+++ b/tests/gpt-header-move
@@ -3,20 +3,21 @@
 # open img file, subtract 33 from altlba address, and move the last 33 sectors
 # back by 33 sectors
 
-from struct import *
+from struct import unpack_from, pack_into
 from zipfile import crc32
 import array
 import sys
+
 file = open(sys.argv[1],'rb+')
 file.seek(512)
 gptheader = file.read(512)
-altlba = unpack_from('<q', gptheader,offset=32)[0]
-gptheader = array.array('c',gptheader)
+altlba = unpack_from('<q', gptheader, offset=32)[0]
+gptheader = array.array('B', gptheader)
 pack_into('<Q', gptheader, 32, altlba-33)
 #zero header crc
 pack_into('<L', gptheader, 16, 0)
 #compute new crc
-newcrc = ((crc32(buffer(gptheader,0,92))) & 0xFFFFFFFF)
+newcrc = ((crc32(gptheader[:92])) & 0xFFFFFFFF)
 pack_into('<L', gptheader, 16, newcrc)
 file.seek(512)
 file.write(gptheader)
@@ -25,7 +26,7 @@ gptheader = file.read(512)
 file.seek(512*(altlba-32))
 backup = file.read(512*32)
 altlba -= 33
-gptheader = array.array('c',gptheader)
+gptheader = array.array('B',gptheader)
 #update mylba
 pack_into('<Q', gptheader, 24, altlba)
 #update table lba
@@ -33,9 +34,9 @@ pack_into('<Q', gptheader, 72, altlba-32)
 #zero header crc
 pack_into('<L', gptheader, 16, 0)
 #compute new crc
-newcrc = ((crc32(buffer(gptheader,0,92))) & 0xFFFFFFFF)
+newcrc = ((crc32(gptheader[:92])) & 0xFFFFFFFF)
 pack_into('<L', gptheader, 16, newcrc)
 file.seek(512*(altlba-32))
 file.write(backup)
 file.write(gptheader)
-file.write("\0" * (512 * 33))
+file.write(b"\0" * (512 * 33))
diff --git a/tests/msdos-overlap b/tests/msdos-overlap
index 5bddfb0..d6ae8d6 100755
--- a/tests/msdos-overlap
+++ b/tests/msdos-overlap
@@ -14,12 +14,11 @@ BAD_ENTRY = (0x72, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 OFFSET = 0x1b8
 
 if len(sys.argv) < 2:
-    print "%s: <image or device>"
+    print("%s: <image or device>" % sys.argv[0])
     sys.exit(1)
 
-data = "".join(chr(c) for c in BAD_ENTRY)
 with open(sys.argv[1], "rb+") as f:
     f.seek(OFFSET, 0)
-    f.write(data)
+    f.write(bytes(bytearray(BAD_ENTRY)))
 
 sys.exit(0)
-- 
2.17.1