Convert py scripts for py2 and py3 compatibility (#13931)

This commit is contained in:
Alexey Shvetsov 2019-05-08 04:45:01 +03:00 committed by Scott Lahteine
parent 11adcf1ce3
commit af725c81e3
4 changed files with 51 additions and 39 deletions

View file

@ -1,3 +1,4 @@
#!/usr/bin/env python
# #
# Builds custom upload command # Builds custom upload command
# 1) Run platformio as a subprocess to find a COM port # 1) Run platformio as a subprocess to find a COM port
@ -9,6 +10,9 @@
# Will continue on if a COM port isn't found so that the compilation can be done. # Will continue on if a COM port isn't found so that the compilation can be done.
# #
from __future__ import print_function
from __future__ import division
import subprocess import subprocess
import os import os
import sys import sys
@ -45,7 +49,7 @@ else:
global description_CDC global description_CDC
print '\nLooking for Serial Port\n' print('\nLooking for Serial Port\n')
# stream output from subprocess and split it into lines # stream output from subprocess and split it into lines
pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@ -78,10 +82,10 @@ else:
com_CDC = com_CDC.replace('\r', '') com_CDC = com_CDC.replace('\r', '')
if com_CDC == 'COM_PORT_NOT_FOUND': if com_CDC == 'COM_PORT_NOT_FOUND':
print com_CDC, '\n' print(com_CDC, '\n')
else: else:
print 'FOUND: ' ,com_CDC print('FOUND: ' ,com_CDC)
print 'DESCRIPTION: ', description_CDC , '\n' print('DESCRIPTION: ', description_CDC , '\n')
if current_OS == 'Windows': if current_OS == 'Windows':
@ -114,7 +118,7 @@ else:
# upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i' # upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i' upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
print 'upload_string: ', upload_string print('upload_string: ', upload_string)

View file

@ -1,5 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
from __future__ import division
""" Generate the stepper delay lookup table for Marlin firmware. """ """ Generate the stepper delay lookup table for Marlin firmware. """
import argparse import argparse
@ -16,35 +19,35 @@ args = parser.parse_args()
cpu_freq = args.cpu_freq * 1000000 cpu_freq = args.cpu_freq * 1000000
timer_freq = cpu_freq / args.divider timer_freq = cpu_freq / args.divider
print "#ifndef SPEED_LOOKUPTABLE_H" print("#ifndef SPEED_LOOKUPTABLE_H")
print "#define SPEED_LOOKUPTABLE_H" print("#define SPEED_LOOKUPTABLE_H")
print print()
print '#include "Marlin.h"' print('#include "Marlin.h"')
print print()
print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {" print("const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {")
a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ] a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
b = [ a[i] - a[i+1] for i in range(255) ] b = [ a[i] - a[i+1] for i in range(255) ]
b.append(b[-1]) b.append(b[-1])
for i in range(32): for i in range(32):
print " ", print(" ", end=' ')
for j in range(8): for j in range(8):
print "{%d, %d}," % (a[8*i+j], b[8*i+j]), print("{%d, %d}," % (a[8*i+j], b[8*i+j]), end=' ')
print print()
print "};" print("};")
print print()
print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {" print("const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {")
a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ] a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
b = [ a[i] - a[i+1] for i in range(255) ] b = [ a[i] - a[i+1] for i in range(255) ]
b.append(b[-1]) b.append(b[-1])
for i in range(32): for i in range(32):
print " ", print(" ", end=' ')
for j in range(8): for j in range(8):
print "{%d, %d}," % (a[8*i+j], b[8*i+j]), print("{%d, %d}," % (a[8*i+j], b[8*i+j]), end=' ')
print print()
print "};" print("};")
print print()
print "#endif" print("#endif")

View file

@ -18,6 +18,9 @@ Options:
--num-temps=... the number of temperature points to calculate (default: 36) --num-temps=... the number of temperature points to calculate (default: 36)
""" """
from __future__ import print_function
from __future__ import division
from math import * from math import *
import sys import sys
import getopt import getopt
@ -47,9 +50,9 @@ class Thermistor:
a = y1 - (b + l1**2 *c)*l1 a = y1 - (b + l1**2 *c)*l1
if c < 0: if c < 0:
print "//////////////////////////////////////////////////////////////////////////////////////" print("//////////////////////////////////////////////////////////////////////////////////////")
print "// WARNING: negative coefficient 'c'! Something may be wrong with the measurements! //" print("// WARNING: negative coefficient 'c'! Something may be wrong with the measurements! //")
print "//////////////////////////////////////////////////////////////////////////////////////" print("//////////////////////////////////////////////////////////////////////////////////////")
c = -c c = -c
self.c1 = a # Steinhart-Hart coefficients self.c1 = a # Steinhart-Hart coefficients
self.c2 = b self.c2 = b
@ -97,7 +100,7 @@ def main(argv):
try: try:
opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="]) opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print str(err) print(str(err))
usage() usage()
sys.exit(2) sys.exit(2)
@ -129,27 +132,27 @@ def main(argv):
up_bound = t.temp(1); up_bound = t.temp(1);
min_temp = int(TMIN if TMIN > low_bound else low_bound) min_temp = int(TMIN if TMIN > low_bound else low_bound)
max_temp = int(TMAX if TMAX < up_bound else up_bound) max_temp = int(TMAX if TMAX < up_bound else up_bound)
temps = range(max_temp, TMIN+step, step); temps = list(range(max_temp, TMIN+step, step));
print "// Thermistor lookup table for Marlin" print("// Thermistor lookup table for Marlin")
print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps) print("// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps))
print "// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3) print("// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3))
print "// Theoretical limits of thermistor: %.2f to %.2f degC" % (low_bound, up_bound) print("// Theoretical limits of thermistor: %.2f to %.2f degC" % (low_bound, up_bound))
print print()
print "const short temptable[][2] PROGMEM = {" print("const short temptable[][2] PROGMEM = {")
for temp in temps: for temp in temps:
adc = t.adc(temp) adc = t.adc(temp)
print " { OV(%7.2f), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \ print(" { OV(%7.2f), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \
',' if temp != temps[-1] else ' ', \ ',' if temp != temps[-1] else ' ', \
t.voltage(adc), \ t.voltage(adc), \
t.resist( adc), \ t.resist( adc), \
t.resol( adc) \ t.resol( adc) \
) ))
print "};" print("};")
def usage(): def usage():
print __doc__ print(__doc__)
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])

View file

@ -1,10 +1,12 @@
#!/usr/bin/python3 #!/usr/bin/python
# This file is for preprocessing gcode and the new G29 Autobedleveling from Marlin # This file is for preprocessing gcode and the new G29 Autobedleveling from Marlin
# It will analyse the first 2 Layer and return the maximum size for this part # It will analyse the first 2 Layer and return the maximum size for this part
# After this it will replace with g29_keyword = ';MarlinG29Script' with the new G29 LRFB # After this it will replace with g29_keyword = ';MarlinG29Script' with the new G29 LRFB
# the new file will be created in the same folder. # the new file will be created in the same folder.
from __future__ import print_function
# your gcode-file/folder # your gcode-file/folder
folder = './' folder = './'
my_file = 'test.gcode' my_file = 'test.gcode'