summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBrian C. Lane <bcl@redhat.com>2018-06-27 13:45:09 -0700
committerBrian C. Lane <bcl@redhat.com>2018-08-22 11:34:47 -0700
commit554d54cf7dbed387ace44a733c535c08d645bf9a (patch)
treed49b343440da887238808e4a322f7cca803e1db3 /tests
parent93684aeb12cf96e5bfefa405940c3010f60161b1 (diff)
downloadparted-554d54cf7dbed387ace44a733c535c08d645bf9a.tar.gz
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
Diffstat (limited to 'tests')
-rwxr-xr-xtests/gpt-header-move15
-rwxr-xr-xtests/msdos-overlap5
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)