1 From 073c24b5d2361857b8ce8b5dcd81a3e26fc05b96 Mon Sep 17 00:00:00 2001
2 From: "Brian C. Lane" <bcl@redhat.com>
3 Date: Wed, 27 Jun 2018 13:45:09 -0700
4 Subject: [PATCH 91/92] Modify gpt-header-move and msdos-overlap to work with
7 Distributions are starting to remove python2 and only use python3.
8 Modify these test scripts so that they will work with either python 2.7
11 tests/gpt-header-move | 15 ++++++++-------
12 tests/msdos-overlap | 5 ++---
13 2 files changed, 10 insertions(+), 10 deletions(-)
15 diff --git a/tests/gpt-header-move b/tests/gpt-header-move
16 index 05cdc65..3dda5cb 100755
17 --- a/tests/gpt-header-move
18 +++ b/tests/gpt-header-move
20 # open img file, subtract 33 from altlba address, and move the last 33 sectors
24 +from struct import unpack_from, pack_into
25 from zipfile import crc32
29 file = open(sys.argv[1],'rb+')
31 gptheader = file.read(512)
32 -altlba = unpack_from('<q', gptheader,offset=32)[0]
33 -gptheader = array.array('c',gptheader)
34 +altlba = unpack_from('<q', gptheader, offset=32)[0]
35 +gptheader = array.array('B', gptheader)
36 pack_into('<Q', gptheader, 32, altlba-33)
38 pack_into('<L', gptheader, 16, 0)
40 -newcrc = ((crc32(buffer(gptheader,0,92))) & 0xFFFFFFFF)
41 +newcrc = ((crc32(gptheader[:92])) & 0xFFFFFFFF)
42 pack_into('<L', gptheader, 16, newcrc)
45 @@ -25,7 +26,7 @@ gptheader = file.read(512)
46 file.seek(512*(altlba-32))
47 backup = file.read(512*32)
49 -gptheader = array.array('c',gptheader)
50 +gptheader = array.array('B',gptheader)
52 pack_into('<Q', gptheader, 24, altlba)
54 @@ -33,9 +34,9 @@ pack_into('<Q', gptheader, 72, altlba-32)
56 pack_into('<L', gptheader, 16, 0)
58 -newcrc = ((crc32(buffer(gptheader,0,92))) & 0xFFFFFFFF)
59 +newcrc = ((crc32(gptheader[:92])) & 0xFFFFFFFF)
60 pack_into('<L', gptheader, 16, newcrc)
61 file.seek(512*(altlba-32))
64 -file.write("\0" * (512 * 33))
65 +file.write(b"\0" * (512 * 33))
66 diff --git a/tests/msdos-overlap b/tests/msdos-overlap
67 index 5bddfb0..d6ae8d6 100755
68 --- a/tests/msdos-overlap
69 +++ b/tests/msdos-overlap
70 @@ -14,12 +14,11 @@ BAD_ENTRY = (0x72, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 - print "%s: <image or device>"
75 + print("%s: <image or device>" % sys.argv[0])
78 -data = "".join(chr(c) for c in BAD_ENTRY)
79 with open(sys.argv[1], "rb+") as f:
82 + f.write(bytes(bytearray(BAD_ENTRY)))