From 54e9eb297c36e412137c2ce6d250d3bdaaf7951c Mon Sep 17 00:00:00 2001
From: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Date: Fri, 20 Jul 2018 20:54:43 +0200
Subject: [PATCH] libnxt-switch-from-using-python2-to-python3
---
make_flash_header.py | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/make_flash_header.py b/make_flash_header.py
index 9734c86..8068c94 100755
--- a/make_flash_header.py
+++ b/make_flash_header.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Take the flash_routine.bin file, and embed it as an array of bytes
# in a flash_routine.h, ready for packaging with the C firmware
@@ -11,8 +11,8 @@
import sys
import os
import os.path
-import urllib2
-import sha
+import urllib.request, urllib.parse, urllib.error
+import hashlib
FLASH_DIR = 'flash_write'
FLASH_BIN = 'flash.bin'
@@ -24,7 +24,7 @@ DOWNLOAD_FLASH_URL = 'http://libnxt.googlecode.com/files/flash.bin'
def check_flash_size():
statinfo = os.stat(FLASH_PATH)
if statinfo.st_size > 1024:
- print "The flash driver looks too big, refusing to embed."
+ print("The flash driver looks too big, refusing to embed.")
return False
return True
@@ -35,7 +35,7 @@ def ensure_flash_bin():
# If the binary doesn't exist, offer to download a binary build
# from Google Code.
- print """
+ print("""
Embedded flash driver not found. This is required to build LibNXT.
If you have an ARM7 cross-compiler toolchain available, you can build
@@ -46,21 +46,21 @@ and everything should work great.
If you do not have a cross-compiler, do not despair! I can also
download a copy of the compiled driver (built by the libnxt developer)
from the project website and use that.
-"""
- reply = raw_input("Is that okay? (y/n) ")
+""")
+ reply = input("Is that okay? (y/n) ")
if reply not in ('y', 'Y', 'yes'):
- print ("Okay, you're the boss. But that does mean I can't build "
+ print("Okay, you're the boss. But that does mean I can't build "
"LibNXT. Sorry.")
return False
- f = urllib2.urlopen(DOWNLOAD_FLASH_URL)
+ f = urllib.request.urlopen(DOWNLOAD_FLASH_URL)
data = f.read()
f.close()
# Verify the SHA-1 checksum
- checksum = sha.new(data).hexdigest()
+ checksum = hashlib.sha1(data).hexdigest()
if checksum != DOWNLOAD_FLASH_CHECKSUM:
- print "Oops, the flash binary I downloaded has the wrong checksum!"
- print "Aborting :("
+ print("Oops, the flash binary I downloaded has the wrong checksum!")
+ print("Aborting :(")
return False
f = open(FLASH_PATH, 'w')
@@ -78,11 +78,11 @@ def main():
if not ensure_flash_bin():
sys.exit(1)
- f = file(FLASH_PATH)
+ f = open(FLASH_PATH, 'rb')
fwbin = f.read()
f.close()
- data = ['0x%s' % c.encode('hex') for c in fwbin]
+ data = ['0x%02x' % c for c in fwbin]
for i in range(0, len(data), 12):
data[i] = "\n " + data[i]
@@ -91,7 +91,7 @@ def main():
len_data = "%d" % len(data)
# Read in the template
- tplfile = file('flash_routine.h.base')
+ tplfile = open('flash_routine.h.base')
template = tplfile.read()
tplfile.close()
@@ -100,7 +100,7 @@ def main():
template = template.replace('___FLASH_LEN___', len_data)
# Output the done header
- out = file('flash_routine.h', 'w')
+ out = open('flash_routine.h', 'w')
out.write(template)
out.close()
--
2.17.1