diff --git a/radio/util/add-issue-links.py b/radio/util/add-issue-links.py index e66ad56a7..d2682bce3 100755 --- a/radio/util/add-issue-links.py +++ b/radio/util/add-issue-links.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function import sys import os @@ -43,7 +44,7 @@ while True: links = "(" + ", ".join(issue_links) + ")" line = "
  • " + line + " " + links + "
  • " - print line + print(line) inp.close() diff --git a/radio/util/addtr.py b/radio/util/addtr.py index 3a3b30e52..4794b8905 100755 --- a/radio/util/addtr.py +++ b/radio/util/addtr.py @@ -1,9 +1,11 @@ #!/bin/env python +from __future__ import print_function + import sys, glob def addLine(filename, newline, after): - print filename, newline + print(filename, newline) lines = file(filename, 'r').readlines() for i, line in enumerate(lines): if after in line: @@ -14,7 +16,7 @@ def addLine(filename, newline, after): def modifyTranslations(constant, translation, after): for filename in glob.glob('translations/*.h.txt'): newline = "#define " + constant + " "*max(1, 23-len(constant)) + '"' + translation + '"' - addLine(filename, newline, after+" ") + addLine(filename, newline, after+" ") def modifyDeclaration(constant, after): newline = "extern const pm_char S" + constant + "[];" diff --git a/radio/util/codecs.py b/radio/util/codecs.py index 4c75a6ed6..55698b81a 100755 --- a/radio/util/codecs.py +++ b/radio/util/codecs.py @@ -1,5 +1,7 @@ #!/bin/env python +from __future__ import print_function + SIGN_BIT = (0x80) # Sign bit for a A-law byte. QUANT_MASK = (0xf) # Quantization field mask. SEG_SHIFT = (4) # Left shift for segment number. @@ -47,5 +49,5 @@ def tableToString(name, table): result += ' };' return result -print tableToString('alawTable', pcmTable(alaw2linear)) -print tableToString('ulawTable', pcmTable(ulaw2linear)) +print(tableToString('alawTable', pcmTable(alaw2linear))) +print(tableToString('ulawTable', pcmTable(ulaw2linear))) diff --git a/radio/util/copyright.py b/radio/util/copyright.py index 9a12c285d..3e075d08f 100755 --- a/radio/util/copyright.py +++ b/radio/util/copyright.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + import os import re import sys @@ -38,9 +40,9 @@ def writeheader(filename,header): f = open(filename,'w') f.writelines(output) f.close() - print "added header to %s" %filename - except IOError,err: - print "something went wrong trying to add header to %s: %s" % (filename,err) + print("added header to %s" %filename) + except IOError as err: + print("something went wrong trying to add header to %s: %s" % (filename,err)) def main(args=sys.argv): headerfile = open(args[1]) diff --git a/radio/util/dsm2.py b/radio/util/dsm2.py index 1d1d77006..7c5e4097a 100755 --- a/radio/util/dsm2.py +++ b/radio/util/dsm2.py @@ -1,7 +1,9 @@ +from __future__ import print_function + BITLEN_DSM2 = 16 def sendByteDsm2(b): - print "%02x:" % b, + print("%02x:" % b, end=' ') lev = 0 len = BITLEN_DSM2 for i in range(9): @@ -9,13 +11,13 @@ def sendByteDsm2(b): if (lev == nlev): len += BITLEN_DSM2 else: - print len, + print(len, end=' ') # _send_1(nlev ? len-5 : len+3); len = BITLEN_DSM2 lev = nlev b = (b>>1) | 0x80 # _send_1(len+BITLEN_DSM2+3); // 2 stop bits - print len+BITLEN_DSM2 + print(len+BITLEN_DSM2) sendByteDsm2(24) sendByteDsm2(17) diff --git a/radio/util/fat12.py b/radio/util/fat12.py index 13889f3c7..fdc81d235 100755 --- a/radio/util/fat12.py +++ b/radio/util/fat12.py @@ -1,5 +1,7 @@ #!/bin/env python +from __future__ import division, print_function + curr = 0 idx = 0 byte = 0 @@ -10,12 +12,12 @@ def push4bits(val): curr += val << idx idx += 4 if idx == 8: - print "0x%02X," % curr, + print("0x%02X," % curr, end=' ') idx = 0 curr = 0 byte += 1 if byte % 16 == 0: - print + print() cluster = 0 @@ -27,8 +29,8 @@ def pushCluster(val): cluster += 1 def pushFile(size): - sectors = size / 512 - count = sectors / 8 + sectors = size // 512 + count = sectors // 8 for i in range(count-1): pushCluster(cluster+1) pushCluster(0xFFF) @@ -36,14 +38,14 @@ def pushFile(size): def pushDisk(eeprom, flash): global curr, idx, byte, cluster curr = idx = byte = cluster = 0 - print "Disk with %dk EEPROM and %dk FLASH:" % (eeprom, flash) + print("Disk with %dk EEPROM and %dk FLASH:" % (eeprom, flash)) pushCluster(0xFF8) pushCluster(0xFFF) pushFile(eeprom*1024) pushFile(flash*1024) while byte < 512: push4bits(0) - print + print() pushDisk(32, 512) pushDisk(64, 512) diff --git a/radio/util/img2lbm.py b/radio/util/img2lbm.py index e02ac7a25..58e12e32c 100755 --- a/radio/util/img2lbm.py +++ b/radio/util/img2lbm.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import division, print_function + import sys from PyQt4 import Qt, QtGui @@ -19,7 +21,7 @@ else: def writeSize(f, width, height): if lcdwidth > 255: - f.write("%d,%d,%d,%d,\n" % (width%256, width/256, height%256, height/256)) + f.write("%d,%d,%d,%d,\n" % (width%256, width//256, height%256, height//256)) else: f.write("%d,%d,\n" % (width, height)) @@ -27,7 +29,7 @@ if what == "1bit": rows = 1 if len(sys.argv) > 5: rows = int(sys.argv[5]) - writeSize(f, width, height/rows) + writeSize(f, width, height//rows) for y in range(0, height, 8): for x in range(width): value = 0 @@ -42,7 +44,7 @@ elif what == "4/4/4/4": for y in range(height): for x in range(width): pixel = image.pixel(x, y) - f.write("0x%1x%1x%1x%1x," % (Qt.qAlpha(pixel)/16, Qt.qRed(pixel)/16, Qt.qGreen(pixel)/16, Qt.qBlue(pixel)/16)) + f.write("0x%1x%1x%1x%1x," % (Qt.qAlpha(pixel)//16, Qt.qRed(pixel)//16, Qt.qGreen(pixel)//16, Qt.qBlue(pixel)//16)) f.write("\n") elif what == "5/6/5/8": colors = [] @@ -148,4 +150,3 @@ elif what == "22x38": f.write("\n") else: print("wrong argument", sys.argv[4]) - diff --git a/radio/util/include-guard.py b/radio/util/include-guard.py index 53d3bdb9e..77e80bed0 100755 --- a/radio/util/include-guard.py +++ b/radio/util/include-guard.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + import sys, os for filename in sys.argv[1:]: @@ -14,7 +16,7 @@ for filename in sys.argv[1:]: if line.startswith("#ifndef "): guard = line[8:] if lines[i+1].strip() == "#define %s" % guard: - print filename, ":", guard, "=>", newguard + print(filename, ":", guard, "=>", newguard) lines[i] = "#ifndef %s\n" % newguard lines[i+1] = "#define %s\n" % newguard end = -1 diff --git a/radio/util/luaexport.py b/radio/util/luaexport.py index 5b785e8bb..e000454ec 100755 --- a/radio/util/luaexport.py +++ b/radio/util/luaexport.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from __future__ import print_function import sys import os @@ -24,11 +25,11 @@ error = None def checkName(name): global warning if name in dups_name: - print "WARNING: Duplicate name %s found for constant %s" % (name, CONSTANT_VALUE) + print("WARNING: Duplicate name %s found for constant %s" % (name, CONSTANT_VALUE)) warning = True dups_name.append(name) if name != name.lower(): - print "WARNING: Name not in lower case %s found for constant %s" % (name, CONSTANT_VALUE) + print("WARNING: Name not in lower case %s found for constant %s" % (name, CONSTANT_VALUE)) warning = True @@ -46,9 +47,9 @@ def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount): exports_multiple.append( (CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount) ) if len(sys.argv) < 3: - print "Error: not enough arguments!" - print "Usage:" - print " luaexport.py []" + print("Error: not enough arguments!") + print("Usage:") + print(" luaexport.py []") version = sys.argv[1] inputFile = sys.argv[2] @@ -56,11 +57,11 @@ outputFile = sys.argv[3] docFile = None if len(sys.argv) >= 4: docFile = sys.argv[4] -print "Version %s" % version -print "Input file %s" % inputFile -print "Output file %s" % outputFile +print("Version %s" % version) +print("Input file %s" % inputFile) +print("Output file %s" % outputFile) if docFile: - print "Documentation file %s" % docFile + print("Documentation file %s" % docFile) inp = open(inputFile, "r") @@ -75,7 +76,7 @@ while True: parts = line.split('LEXP') #print parts if len(parts) != 2: - print "Wrong line: %s" % line + print("Wrong line: %s" % line) continue cmd = 'LEXP' + parts[1] cnst = parts[0].rstrip(', ') @@ -93,7 +94,7 @@ while True: # print cmd eval(cmd) except: - print "ERROR: problem with the definition: %s" % line + print("ERROR: problem with the definition: %s" % line) traceback.print_exc() error = True @@ -130,7 +131,7 @@ exports.sort(key = lambda x: x[1]) #sort by name data = [" {%s, \"%s\", \"%s\"}" % export for export in exports] out.write(",\n".join(data)) out.write("\n};\n\n") -print "Generated %d items in luaFields[]" % len(exports) +print("Generated %d items in luaFields[]" % len(exports)) out.write(""" // The list of Lua fields that have a range of values @@ -139,7 +140,7 @@ const LuaMultipleField luaMultipleFields[] = { data = [" {%s, \"%s\", \"%s\", %d}" % export for export in exports_multiple] out.write(",\n".join(data)) out.write("\n};\n\n") -print "Generated %d items in luaMultipleFields[]" % len(exports_multiple) +print("Generated %d items in luaMultipleFields[]" % len(exports_multiple)) out.close() if docFile: diff --git a/radio/util/parse.py b/radio/util/parse.py index 5d0faac96..cb75901bc 100755 --- a/radio/util/parse.py +++ b/radio/util/parse.py @@ -1,9 +1,11 @@ #!/usr/bin/env python +from __future__ import print_function + import sys filename = sys.argv[1] -print filename +print(filename) fr = open(filename) fw = open(filename+".new", "w") ew = open(filename+".en", "w") @@ -46,10 +48,10 @@ for line in fr.readlines(): if str_rep in replacements.keys(): if replacements[str_rep] != str: - print "!!!!! NON !!!!!" + print("!!!!! NON !!!!!") else: replacements[str_rep] = str - print glob_str, "=>", str, str_rep + print(glob_str, "=>", str, str_rep) ew.write("#define " + str_rep[1:] + " "*(17-len(str_rep)) + '"%s"\n' % str) hw.write("extern const PROGMEM char %s[];\n" % str_rep) cw.write("const prog_char APM %s[] = %s;\n" % (str_rep, str_rep[1:])) diff --git a/radio/util/sinus.py b/radio/util/sinus.py index 727090e49..bea4b3fc0 100755 --- a/radio/util/sinus.py +++ b/radio/util/sinus.py @@ -1,5 +1,7 @@ #!/bin/env python +from __future__ import print_function + import math samples = 1024 @@ -17,13 +19,13 @@ for i in range(samples): max = sample elif sample < min: min = sample - print "%d," % sample, + print("%d," % sample, end=' ') if i % 10 == 9: - print + print() -print -print 'Range is:', min, max +print() +print('Range is:', min, max) if max > 32767 or min < -32768: - print "Invalid range!" + print("Invalid range!") diff --git a/radio/util/sport-parse.py b/radio/util/sport-parse.py index 58c041de5..c11f66a44 100755 --- a/radio/util/sport-parse.py +++ b/radio/util/sport-parse.py @@ -3,6 +3,7 @@ # This program parses sport.log files +from __future__ import division, print_function import os import sys @@ -28,28 +29,28 @@ quiet = False def ParseFlVSS(packet, dataId, prim, appId, data, crc): # if dataId != 0xa1: # return - print "packet: %s (%4d)" % (dump(packet), lineNumber) , + print("packet: %s (%4d)" % (dump(packet), lineNumber), end=' ') cells = (data & 0xF0) >> 4 battnumber = data & 0xF; - voltage1 = ((data & 0x000FFF00) >> 8) / 5 - voltage2 = ((data & 0xFFF00000) >> 20) / 5 - print " FLVSS: no cells: %d, cell: %d: voltages: %0.2f %0.2f" % (cells, battnumber, voltage1/100.0, voltage2/100.0) + voltage1 = ((data & 0x000FFF00) >> 8) // 5 + voltage2 = ((data & 0xFFF00000) >> 20) // 5 + print(" FLVSS: no cells: %d, cell: %d: voltages: %0.2f %0.2f" % (cells, battnumber, voltage1/100., voltage2/100.)) def ParseRSSI(packet, dataId, prim, appId, data, crc): - print "packet: %s (%4d)" % (dump(packet), lineNumber) , - print " RSSI: %d" % (data & 0xFF) + print("packet: %s (%4d)" % (dump(packet), lineNumber), end=' ') + print(" RSSI: %d" % (data & 0xFF)) def ParseAdc(packet, dataId, prim, appId, data, crc): - print "packet: %s (%4d)" % (dump(packet), lineNumber) , - print " A%d: %d" % (dataId - 0xf102, data & 0xFF) + print("packet: %s (%4d)" % (dump(packet), lineNumber), end=' ') + print(" A%d: %d" % (dataId - 0xf102, data & 0xFF)) def ParseBatt(packet, dataId, prim, appId, data, crc): - print "packet: %s (%4d)" % (dump(packet), lineNumber) , - print " Batt: %d" % (data & 0xFF) + print("packet: %s (%4d)" % (dump(packet), lineNumber), end=' ') + print(" Batt: %d" % (data & 0xFF)) def ParseSWR(packet, dataId, prim, appId, data, crc): - print "packet: %s (%4d)" % (dump(packet), lineNumber) , - print " SWR: %d" % (data & 0xFF) + print("packet: %s (%4d)" % (dump(packet), lineNumber), end=' ') + print(" SWR: %d" % (data & 0xFF)) def ParseAirSpeed(packet, dataId, prim, appId, data, crc): print "packet: %s (%4d)" % (dump(packet), lineNumber) , @@ -77,7 +78,7 @@ def ParseSportPacket(packet): (dataId, prim, appId, data, crc) = struct.unpack('= firstId and appId <= lastId: @@ -85,8 +86,8 @@ def ParseSportPacket(packet): return #no parser found if not quiet: - print "\tdataId:%02x, prim:%02x, appId:%04x, data:%08x, crc:%02x)" % (dataId, prim, appId, data, crc) - print "\tparser for appId %02x not implemented" % appId + print("\tdataId:%02x, prim:%02x, appId:%04x, data:%08x, crc:%02x)" % (dataId, prim, appId, data, crc)) + print("\tparser for appId %02x not implemented" % appId) def ParsePacket(packet): global lineNumber @@ -104,7 +105,7 @@ def ParsePacket(packet): #print "buff after unstuff %s" % dump(packet, 20) else: #missin data, wait for more data - print "unstuff missing data" + print("unstuff missing data") return #print "packet: %s" % dump(packet, 10) @@ -113,11 +114,11 @@ def ParsePacket(packet): #print "\npacket: %s @%d" % (dump(packet), lineNumber) #check crc if not CheckSportCrc(packet): - print "error: wrong CRC for packet %s at line %d" % (dump(packet), lineNumber) + print("error: wrong CRC for packet %s at line %d" % (dump(packet), lineNumber)) ParseSportPacket(packet) else: if len(packet) > 1: - print "warning: wrong length %s for packet %s at line %d" % (len(packet), dump(packet, 10), lineNumber) + print("warning: wrong length %s for packet %s at line %d" % (len(packet), dump(packet, 10), lineNumber)) def ParseSportData(data): @@ -169,8 +170,8 @@ while True: #print line parts = line.split(': ') if len(parts) < 2: - print "weird data: \"%s\" at line %d" % (line, lineNumber) + print("weird data: \"%s\" at line %d" % (line, lineNumber)) continue sportData = parts[1].strip() # print "sd: %s" % sportData - ParseSportData(sportData) \ No newline at end of file + ParseSportData(sportData) diff --git a/radio/util/translate.py b/radio/util/translate.py index d0a6f7958..d2ff4cb86 100755 --- a/radio/util/translate.py +++ b/radio/util/translate.py @@ -127,7 +127,7 @@ parser.add_argument("--reverse", help="Reversed char conversion (from number to args = parser.parse_args() if args.language not in translations: - parser.error(args.language + ' is not a supported language. Try one of the supported ones: ' + str(translations.keys())) + parser.error(args.language + ' is not a supported language. Try one of the supported ones: ' + str(list(translations.keys()))) system.exit() if args.reverse: diff --git a/radio/util/tts.py b/radio/util/tts.py index d8eecfc81..6a9c02cf5 100755 --- a/radio/util/tts.py +++ b/radio/util/tts.py @@ -26,7 +26,18 @@ # Portuguese : Romolo Manfredini # Spanish : Romolo Manfredini (With the help of Jose Moreno) -import os, sys, shutil, platform, subprocess, wave, zipfile, httplib, urllib +from __future__ import print_function + +import os, sys, shutil, platform, subprocess, wave, zipfile + +try: + # Python 3 + from http.client import HTTPConnection + from urllib.parse import urlencode +except ImportError: + # Python 2 + from httplib import HTTPConnection + from urllib import urlencode NO_ALTERNATE = 1024 @@ -53,7 +64,7 @@ def wavstrip(filename): def generate(str, filename): - print filename, str + print(filename, str) if not str: str = " !" #this is so blank wav files never exist! @@ -67,7 +78,7 @@ def generate(str, filename): "speak not implemented with google tts engine" exit() else: - print "which speach engine?" + print("which speach engine?") exit() else: if "sapi" in sys.argv: @@ -82,8 +93,8 @@ def generate(str, filename): elif "google" in sys.argv: ttsmp3 = "ttsfile.mp3" ttsfilename = "ttsfile.wav" - conn = httplib.HTTPConnection("translate.google.com") - params = urllib.urlencode({'ie': "UTF-8", 'tl': directory, 'q': str.encode("utf-8")}) + conn = HTTPConnection("translate.google.com") + params = urlencode({'ie': "UTF-8", 'tl': directory, 'q': str.encode("utf-8")}) headers = {"User-Agent": "Mozilla"} conn.request("GET", u"/translate_tts?%s" % params, headers=headers) # conn.request("GET", "/translate_tts?ie=UTF-8&tl=%s&q=%s" % (directory, urllib.urlencode(str)), headers={"User-Agent": "Mozilla"}) @@ -93,7 +104,7 @@ def generate(str, filename): conn.close() else: - print "which speach engine?" + print("which speach engine?") exit() wavstrip(ttsfilename) @@ -771,7 +782,7 @@ if __name__ == "__main__": # tts.Volume = 40 # tts.SetRate(1) if "list" in sys.argv: - print tts.GetVoiceNames() + print(tts.GetVoiceNames()) exit() if "mulaw" in sys.argv: @@ -887,7 +898,7 @@ if __name__ == "__main__": systemSounds, sounds = ttsCz() else: - print "which language?" + print("which language?") exit() if "csv" in sys.argv: