Skip to content

Commit

Permalink
can_boot_descriptor: python3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jlecoeur authored and Julien Lecoeur committed Jul 6, 2017
1 parent 12b43e7 commit f5105e0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Tools/make_can_boot_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import struct
import optparse
import binascii
import cStringIO
from io import BytesIO

class GitWrapper:
@classmethod
Expand Down Expand Up @@ -84,14 +84,17 @@ def __init__(self, path_or_file, mode="r"):
self._do_close = False
self._padding = 0
else:
self._file = open(path_or_file, mode + "b")
if "b" not in mode:
self._file = open(path_or_file, mode + "b")
else:
self._file = open(path_or_file, mode)
self._do_close = True
self._padding = 4

if "r" in mode:
self._contents = cStringIO.StringIO(self._file.read())
self._contents = BytesIO(self._file.read())
else:
self._contents = cStringIO.StringIO()
self._contents = BytesIO()
self._do_write = False

self._length = None
Expand Down Expand Up @@ -152,9 +155,9 @@ def crc(self):
# descriptor zeroed out.
crc_offset = self.app_descriptor_offset + len(AppDescriptor.SIGNATURE)
content = bytearray(self._contents.getvalue())
content[crc_offset:crc_offset + 8] = bytearray("\x00" * 8)
content[crc_offset:crc_offset + 8] = bytearray.fromhex("00" * 8)
if self._padding:
content += bytearray("\xff" * self._padding)
content += bytearray.fromhex("ff" * self._padding)
val = MASK
for byte in content:
val ^= (byte << 56) & MASK
Expand Down Expand Up @@ -261,7 +264,7 @@ def app_descriptor(self, value):
try:
options.vcs_commit = int(GitWrapper.command("rev-list HEAD --max-count=1 --abbrev=8 --abbrev-commit"),16)
except Exception as e:
print "Git Command failed "+ str(e) +"- Exiting!"
print("Git Command failed "+ str(e) +"- Exiting!")
quit()

if args:
Expand All @@ -271,7 +274,7 @@ def app_descriptor(self, value):
in_file = sys.stdin
out_file = sys.stdout

bootloader_image = ""
bootloader_image = b""
if options.bootloader_image:
with open(options.bootloader_image, "rb") as bootloader:
bootloader_image = bootloader.read()
Expand Down

0 comments on commit f5105e0

Please sign in to comment.