First working version: both python2 and python3

This commit is contained in:
Shahram Najm 2017-01-25 11:53:23 +00:00
parent f020620c1e
commit 03ba1a520d
1 changed files with 13 additions and 3 deletions

View File

@ -3,6 +3,7 @@ from __future__ import print_function
import os
import re
import sys
import binascii
assert len(sys.argv) > 2
@ -37,10 +38,19 @@ for directory in dirs:
print('static const unsigned char %s[] = {' % (name,), file=g)
with open(full) as f:
with open(full, 'rb') as f:
i = 0
for n in re.findall('..', f.read().encode("hex")):
print("0x%s," % (n,), end="", file=g)
#Python 2
#fcont = f.read().encode("hex")
#Python 2 and 3
fcont = binascii.hexlify(f.read())
for n in range(0, len(fcont), 2):
twoChars = fcont[n:n+2]
if sys.version_info.major > 2:
twoChars = str(twoChars,'ascii')
print("0x%s," % (twoChars,), end="", file=g)
i += 1
if (i % 20) == 0:
print("", file=g)