From 149ee4a2eb450b430ca18710eb558cdbcd9e7c69 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 22 Nov 2018 14:11:56 -0500 Subject: [PATCH] python 2->3 for tools --- tools/checkpresets.py | 4 ++-- tools/lfsrcalc.py | 2 +- tools/midi2song.py | 32 ++++++++++++++++---------------- tools/mknotes.py | 10 +++++----- tools/mknotes2600.py | 19 ++++++++----------- tools/p4_to_48pix.py | 18 +++++++++--------- tools/p4_to_pfbytes.py | 24 +++++++++++------------- tools/parsebdf3x5.py | 15 +++++++-------- tools/parsebdf4bit.py | 10 +++++----- tools/parsebdf8.py | 20 ++++++++++---------- tools/pbm_to_c.py | 4 ++-- tools/pcx2will.py | 14 +++++++------- tools/sintbl.py | 4 ++-- tools/svg2vector.py | 10 +++++----- 14 files changed, 90 insertions(+), 96 deletions(-) diff --git a/tools/checkpresets.py b/tools/checkpresets.py index 262748c9..08362747 100644 --- a/tools/checkpresets.py +++ b/tools/checkpresets.py @@ -10,7 +10,7 @@ for root, dirs, files in os.walk("./presets"): with open(path,'r') as f: data = f.read() if data[0] != '\n': - print(path,'no initial newline') + print((path,'no initial newline')) except: - print(path,sys.exc_info()[0]) + print((path,sys.exc_info()[0])) diff --git a/tools/lfsrcalc.py b/tools/lfsrcalc.py index 309f271d..d815a44d 100755 --- a/tools/lfsrcalc.py +++ b/tools/lfsrcalc.py @@ -27,4 +27,4 @@ for n in range(1,MAXBITS): seqindex = seq.index(x) seqlen = len(seq) - seqindex if seqlen>1: - print(seqlen, "#(%d,%d'%s,%d)" % (n,n,bin(i)[1:],invert), seqindex) + print((seqlen, "#(%d,%d'%s,%d)" % (n,n,bin(i)[1:],invert), seqindex)) diff --git a/tools/midi2song.py b/tools/midi2song.py index 8b438b28..8f8b6acd 100755 --- a/tools/midi2song.py +++ b/tools/midi2song.py @@ -71,7 +71,7 @@ def find_common_substrings(s): def get_best_substring(ss): best = (0,0,0) - for k,v in ss.items(): + for k,v in list(ss.items()): if v[0] > best[2]: best = (k,v[1],v[0]) return best @@ -88,7 +88,7 @@ def replace_substrings(s, bss): i,l,n = bss count = (n+1)/(l-1) match = s[i:i+l] - print i,l,n,count,repr(match) + print((i,l,n,count,repr(match))) r = s[0:i] while i %d bytes" % (len(output), len(zout)) + print((','.join([hex2(ord(x)) for x in zout]))) + print(("// compressed %d -> %d bytes" % (len(output), len(zout)))) diff --git a/tools/mknotes.py b/tools/mknotes.py index 9bdab910..d676e94e 100755 --- a/tools/mknotes.py +++ b/tools/mknotes.py @@ -35,14 +35,14 @@ for a440 in range(4300,4500): results.sort() best_error, best_a440 = results[0] best_a440 /= 10.0 -print '//', args -print '//', best_a440, best_error, test_notes +print('//', args) +print('//', best_a440, best_error, test_notes) -print "const int note_table[%d] = {" % final_notes +print("const int note_table[%d] = {" % final_notes) for note in range(0,final_notes): notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0); period = int(round(basehz / notehz)) - bias while period > maxval: period /= 2 - print '%d,' % period, -print "};" + print('%d,' % period, end='') +print("};") diff --git a/tools/mknotes2600.py b/tools/mknotes2600.py index efcb6e05..ab4dbb5b 100755 --- a/tools/mknotes2600.py +++ b/tools/mknotes2600.py @@ -45,21 +45,18 @@ for a440 in range(4200,4600): if period3 < s or period3 > 32*s: tonehz3 = -10000 error += min(abs(notehz-tonehz), abs(notehz-tonehz2), abs(notehz-tonehz3)) - #print a440,note,notehz,notehz-tonehz,period - #if a440 == 4405: - # print '%d,%f,%d' % (note,tonehz-notehz,period) results.append((error, a440)) results.sort() best_error, best_a440 = results[0] best_a440 /= 10.0 -print '//', best_a440, best_error, test_notes +print('//', best_a440, best_error, test_notes) periods = [] tones = [] bits = [] -print "const int note_table[%d] = {" % final_notes +print("const int note_table[%d] = {" % final_notes) for note in range(0,final_notes): notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0); bestperiod = 255 @@ -75,8 +72,8 @@ for note in range(0,final_notes): bestperiod = period besthz = hz - #print '%d,' % period, - print note, besthz, bestperiod, notehz + #print(note, besthz, bestperiod, notehz) + print('%d,' % period, end='') periods.append(bestperiod / s - 1) bits.append(bittable[bestperiod & (s-1)]) if besthz==basehz: @@ -87,8 +84,8 @@ for note in range(0,final_notes): tones.append(6) else: tones.append(0) -print "};" +print("};") -print periods -print bits -print tones +print(periods) +print(bits) +print(tones) diff --git a/tools/p4_to_48pix.py b/tools/p4_to_48pix.py index e3ad5f82..35ba6c7c 100755 --- a/tools/p4_to_48pix.py +++ b/tools/p4_to_48pix.py @@ -23,15 +23,15 @@ def out(i, pix, lb, hb, reverse=0, shift=0): with open(sys.argv[1],'rb') as f: # read PBM header header = f.readline().strip() - assert(header == 'P4') + assert(header == b'P4') dims = f.readline().strip() - if dims[0] == '#': + if dims[0:1] == b'#': dims = f.readline().strip() - width,height = map(int, dims.split()) + width,height = list(map(int, dims.split())) assert(width==48) # read bitmap rows for y in range(0,height): - row = bytes(f.read(6) + '\0\0') # pad to 8 bytes + row = bytes(f.read(6) + b'\0\0') # pad to 8 bytes # convert to 64-bit integer pix = struct.unpack('5: - print s + print(s) diff --git a/tools/p4_to_pfbytes.py b/tools/p4_to_pfbytes.py index f7379543..0586a12f 100755 --- a/tools/p4_to_pfbytes.py +++ b/tools/p4_to_pfbytes.py @@ -23,22 +23,22 @@ def out(i, pix, lb, hb, reverse=0, shift=0): with open(sys.argv[1],'rb') as f: # read PBM header header = f.readline().strip() - assert(header == 'P4') + assert(header == b'P4') dims = f.readline().strip() - if dims[0] == '#': + if dims[0:1] == b'#': dims = f.readline().strip() - width,height = map(int, dims.split()) + print(dims) + width,height = list(map(int, dims.split())) assert(width==40) # read bitmap rows for y in range(0,height): - row = bytes(f.read(5) + '\0\0\0') # pad to 8 bytes + row = bytes(f.read(5) + b'\0\0\0') # pad to 8 bytes # convert bytes from MSB first to LSB first - row2 = '' + row2 = [] for i in range(0,8): - row2 += chr(rev(ord(row[i]))) + row2.append(rev(row[i])) # convert to 64-bit integer - pix = struct.unpack('5: - print s + print(s) diff --git a/tools/parsebdf3x5.py b/tools/parsebdf3x5.py index 16d1c7a5..a14dc131 100755 --- a/tools/parsebdf3x5.py +++ b/tools/parsebdf3x5.py @@ -13,7 +13,6 @@ with open(sys.argv[1],'r') as f: for l in lines: l = l.strip() toks = l.split() - #print l,toks if toks[0] == 'ENCODING': chord = int(toks[1]) elif toks[0] == 'BITMAP': @@ -26,7 +25,7 @@ with open(sys.argv[1],'r') as f: bytes.insert(0,0) assert(len(bytes) == height) bytes.reverse() - print chord,bytes + print((chord,bytes)) chars[chord] = bytes elif inbitmap and len(toks) == 1: byte = int(toks[0],16) @@ -63,10 +62,10 @@ def tohex2(v): def tobin(v): return "bitarray[0][0]=3'b{0:3b};\n".format(v) -print '\thex ' + string.join(map(tohex,output),'') -print string.join(map(tohex2,output),',') -print '\thex ' + string.join(map(tohex,outputlo),'') -print '\thex ' + string.join(map(tohex,outputhi),'') -print string.join(map(tobin,output),'') +print(('\thex ' + ''.join(map(tohex,output)))) +print((''.join(map(tohex2,output)))) +print(('\thex ' + ''.join(map(tohex,outputlo)))) +print(('\thex ' + ''.join(map(tohex,outputhi)))) +print((''.join(map(tobin,output)))) -print len(output),len(outputlo),len(outputhi) +print((len(output),len(outputlo),len(outputhi))) diff --git a/tools/parsebdf4bit.py b/tools/parsebdf4bit.py index 72d9e590..c0d39f97 100755 --- a/tools/parsebdf4bit.py +++ b/tools/parsebdf4bit.py @@ -50,16 +50,16 @@ with open(args.bdffile,'r') as f: if bytes[y] & (0x40 >> x): b |= 0x0f output.append(b) - print 'const char CH_%d[] = { %s };' % ( chord, string.join([tohex2(x) for x in output], ',') ) + print('const char CH_%d[] = { %s };' % ( chord, string.join([tohex2(x) for x in output], ',') )) chars[chord] = 'CH_%d' % chord elif inbitmap and len(toks) == 1: byte = int(toks[0],16) bytes.append(byte) -print 'const char* const FONT_TABLE[%d] = {' % (hichar-lochar+1), +print('const char* const FONT_TABLE[%d] = {' % (hichar-lochar+1), end=' ') for ch in range(lochar, hichar+1): if chars.get(ch): - print '%s,' % chars[ch], + print('%s,' % chars[ch], end=' ') else: - print '0,', -print "};" + print('0,', end=' ') +print("};") diff --git a/tools/parsebdf8.py b/tools/parsebdf8.py index f517e3bf..60db64b4 100755 --- a/tools/parsebdf8.py +++ b/tools/parsebdf8.py @@ -99,20 +99,20 @@ def tohexv(v): for arr in [output]: if args.asmhex: - print '\thex ' + string.join(map(tohex,arr),'') + print('\thex ' + string.join(list(map(tohex,arr)),'')) if args.asmdb: for i in range(0,len(output),height): - print '.DB', string.join(map(tohex2,arr[i:i+height]),','), ';%d'%(i/height+lochar) + print('.DB', string.join(list(map(tohex2,arr[i:i+height])),','), ';%d'%(i/height+lochar)) if args.carray: - print "static char FONT[%d][%d] = {" % (hichar-lochar+1, height) + print("static char FONT[%d][%d] = {" % (hichar-lochar+1, height)) for i in range(0,len(output),height): - print '{', string.join(map(tohex2,arr[i:i+height]),','), '},', - print - print "};" + print('{', string.join(list(map(tohex2,arr[i:i+height])),','), '},', end=' ') + print() + print("};") if args.flatcarray: - print "static char FONT[%d] = {" % ((hichar-lochar+1) * height) - print string.join(map(tohex2,arr),',') - print "}"; + print("static char FONT[%d] = {" % ((hichar-lochar+1) * height)) + print(string.join(list(map(tohex2,arr)),',')) + print("}"); if args.verilog: j = 0 for i in range(0,len(output),height): @@ -121,5 +121,5 @@ for arr in [output]: #print "rom["+str(j)+"] = 32'h" + string.join(map(tohex,arr[i+height/2:i+height]),'') + ";" #j += 1 #print "rom["+str(j)+"] = 64'h" + string.join(map(tohex,arr[i:i+height]),'') + ";" - print string.join(map(tohexv,arr[i:i+height]),',') + ", //%d" % (i/height) + print(string.join(list(map(tohexv,arr[i:i+height])),',') + ", //%d" % (i/height)) j += 1 diff --git a/tools/pbm_to_c.py b/tools/pbm_to_c.py index 85939864..aa6e0df6 100755 --- a/tools/pbm_to_c.py +++ b/tools/pbm_to_c.py @@ -27,11 +27,11 @@ with open(sys.argv[1],'rb') as f: width,height = map(int, dims.split()) wbytes = (width+7)/8 data = f.read() - print "{%d,%d," % (wbytes,height), + print("{%d,%d," % (wbytes,height), end='') for i in range(0,len(data)): if i>0: sys.stdout.write(",") ofs = i+wbytes-(i%wbytes)*2-1 sys.stdout.write( "0x%02x" % ord(data[ofs]) ) - print "}" + print("}") diff --git a/tools/pcx2will.py b/tools/pcx2will.py index 4f08ccf7..fb7cfb8a 100755 --- a/tools/pcx2will.py +++ b/tools/pcx2will.py @@ -19,21 +19,21 @@ with open(sys.argv[1],'rb') as f: assert data[3] == 8 # palette - print "byte palette[16] = {", + print("byte palette[16] = {", end='') for i in range(0,16): r = data[16+i*3] g = data[17+i*3] b = data[18+i*3] entry = (r>>5) | ((g>>2)&0x38) | (b&0xc0) - print '%s,' % (tohex2(entry)), - print "}" + print('%s,' % (tohex2(entry)), end='') + print("}") # image data width = (data[9] << 8) + data[8] + 1 height = (data[11] << 8) + data[10] + 1 rowlen = (data[0x43] << 8) + data[0x42] - print "const byte sprite[] = {" - print "%d,%d," % ((width+1)/2,height) + print("const byte sprite[] = {") + print("%d,%d," % ((width+1)/2,height)) for y in range(0,height): ofs = 0x80 + y*rowlen output = [] @@ -41,6 +41,6 @@ with open(sys.argv[1],'rb') as f: b = (tocolor(data[ofs]) << 4) + tocolor(data[ofs+1]) output.append(b) ofs += 2 - print string.join(map(tohex2,output),',') + ',' - print "}" + print(','.join(map(tohex2,output)) + ',') + print("}") diff --git a/tools/sintbl.py b/tools/sintbl.py index 924bea7b..9140a642 100644 --- a/tools/sintbl.py +++ b/tools/sintbl.py @@ -11,6 +11,6 @@ n = 4 m = 7 for i in range(0,n*4): - print '%d,' % int(round(math.sin(i*math.pi/2/n)*m)), + print('%d,' % int(round(math.sin(i*math.pi/2/n)*m)), end='') if i % 16 == 15: - print + print('') diff --git a/tools/svg2vector.py b/tools/svg2vector.py index fba85793..16e6c47d 100755 --- a/tools/svg2vector.py +++ b/tools/svg2vector.py @@ -14,7 +14,7 @@ def textToColor(name,opacity): return None color = int(name[1:],16) << 8 if opacity: - print 'opacity',opacity + print(('opacity',opacity)) return color svg_file = sys.argv[1] @@ -24,7 +24,7 @@ groups = doc.getElementsByTagName('g') for grp in groups: groupID = grp.getAttribute('id') paths = grp.getElementsByTagName('path') - print groupID,paths + print((groupID,paths)) if len(paths): for path in paths: shape = {} @@ -36,7 +36,7 @@ for grp in groups: nvarr = s.split(':', 2) if len(nvarr) == 2: styleAttrs[nvarr[0]] = nvarr[1] - print path,d,styleAttrs + print((path,d,styleAttrs)) shape['pts'] = [] shape['currentColor'] = textToColor(styleAttrs.get("stroke"), styleAttrs.get("stroke-opacity")) shape['currentWidth'] = textToFloat(styleAttrs.get("strokeWidth")) @@ -47,7 +47,7 @@ for grp in groups: i0 = 0 start = True for cmd in cmds: - print cmd + print(cmd) ch = cmd[0] if ch == 'm' or ch == 'l': start = True @@ -58,7 +58,7 @@ for grp in groups: skip = True else: xy = cmd.split(',') - print xy + print(xy) x += float(xy[0]) y -= float(xy[1]) if start or hidden: