Kaynağa Gözat

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

Alexey Shvetsov 5 yıl önce
ebeveyn
işleme
af725c81e3

+ 9
- 5
buildroot/share/atom/create_custom_upload_command_CDC.py Dosyayı Görüntüle

@@ -1,3 +1,4 @@
1
+#!/usr/bin/env python
1 2
 #
2 3
 #  Builds custom upload command
3 4
 #    1) Run platformio as a subprocess to find a COM port
@@ -9,6 +10,9 @@
9 10
 #  Will continue on if a COM port isn't found so that the compilation can be done.
10 11
 #
11 12
 
13
+from __future__ import print_function
14
+from __future__ import division
15
+
12 16
 import subprocess
13 17
 import os
14 18
 import sys
@@ -45,7 +49,7 @@ else:
45 49
       global description_CDC
46 50
 
47 51
 
48
-      print '\nLooking for Serial Port\n'
52
+      print('\nLooking for Serial Port\n')
49 53
 
50 54
     # stream output from subprocess and split it into lines
51 55
       pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -78,10 +82,10 @@ else:
78 82
         com_CDC = com_CDC.replace('\r', '')
79 83
 
80 84
       if com_CDC == 'COM_PORT_NOT_FOUND':
81
-          print com_CDC, '\n'
85
+          print(com_CDC, '\n')
82 86
       else:
83
-          print 'FOUND: ' ,com_CDC
84
-          print 'DESCRIPTION: ',  description_CDC , '\n'
87
+          print('FOUND: ' ,com_CDC)
88
+          print('DESCRIPTION: ',  description_CDC , '\n')
85 89
 
86 90
   if current_OS == 'Windows':
87 91
 
@@ -114,7 +118,7 @@ else:
114 118
 
115 119
 #      upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
116 120
       upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path  + ' -U flash:w:' + source_path + ':i'
117
-      print 'upload_string: ', upload_string
121
+      print('upload_string: ', upload_string)
118 122
 
119 123
 
120 124
 

+ 21
- 18
buildroot/share/scripts/createSpeedLookupTable.py Dosyayı Görüntüle

@@ -1,5 +1,8 @@
1 1
 #!/usr/bin/env python
2 2
 
3
+from __future__ import print_function
4
+from __future__ import division
5
+
3 6
 """ Generate the stepper delay lookup table for Marlin firmware. """
4 7
 
5 8
 import argparse
@@ -16,35 +19,35 @@ args = parser.parse_args()
16 19
 cpu_freq = args.cpu_freq * 1000000
17 20
 timer_freq = cpu_freq / args.divider
18 21
 
19
-print "#ifndef SPEED_LOOKUPTABLE_H"
20
-print "#define SPEED_LOOKUPTABLE_H"
21
-print
22
-print '#include "Marlin.h"'
23
-print
22
+print("#ifndef SPEED_LOOKUPTABLE_H")
23
+print("#define SPEED_LOOKUPTABLE_H")
24
+print()
25
+print('#include "Marlin.h"')
26
+print()
24 27
 
25
-print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {"
28
+print("const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {")
26 29
 a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
27 30
 b = [ a[i] - a[i+1] for i in range(255) ]
28 31
 b.append(b[-1])
29 32
 for i in range(32):
30
-    print "  ",
33
+    print("  ", end=' ')
31 34
     for j in range(8):
32
-        print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
33
-    print
34
-print "};"
35
-print
35
+        print("{%d, %d}," % (a[8*i+j], b[8*i+j]), end=' ')
36
+    print()
37
+print("};")
38
+print()
36 39
 
37
-print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {"
40
+print("const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {")
38 41
 a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
39 42
 b = [ a[i] - a[i+1] for i in range(255) ]
40 43
 b.append(b[-1])
41 44
 for i in range(32):
42
-    print "  ",
45
+    print("  ", end=' ')
43 46
     for j in range(8):
44
-        print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
45
-    print
46
-print "};"
47
-print
47
+        print("{%d, %d}," % (a[8*i+j], b[8*i+j]), end=' ')
48
+    print()
49
+print("};")
50
+print()
48 51
 
49
-print "#endif"
52
+print("#endif")
50 53
 

+ 18
- 15
buildroot/share/scripts/createTemperatureLookupMarlin.py Dosyayı Görüntüle

@@ -18,6 +18,9 @@ Options:
18 18
   --num-temps=...   the number of temperature points to calculate (default: 36)
19 19
 """
20 20
 
21
+from __future__ import print_function
22
+from __future__ import division
23
+
21 24
 from math import *
22 25
 import sys
23 26
 import getopt
@@ -47,9 +50,9 @@ class Thermistor:
47 50
         a = y1 - (b + l1**2 *c)*l1
48 51
 
49 52
         if c < 0:
50
-            print "//////////////////////////////////////////////////////////////////////////////////////"
51
-            print "// WARNING: negative coefficient 'c'! Something may be wrong with the measurements! //"
52
-            print "//////////////////////////////////////////////////////////////////////////////////////"
53
+            print("//////////////////////////////////////////////////////////////////////////////////////")
54
+            print("// WARNING: negative coefficient 'c'! Something may be wrong with the measurements! //")
55
+            print("//////////////////////////////////////////////////////////////////////////////////////")
53 56
             c = -c
54 57
         self.c1 = a                         # Steinhart-Hart coefficients
55 58
         self.c2 = b
@@ -97,7 +100,7 @@ def main(argv):
97 100
     try:
98 101
         opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
99 102
     except getopt.GetoptError as err:
100
-        print  str(err)
103
+        print(str(err))
101 104
         usage()
102 105
         sys.exit(2)
103 106
 
@@ -129,27 +132,27 @@ def main(argv):
129 132
     up_bound = t.temp(1);
130 133
     min_temp = int(TMIN if TMIN > low_bound else low_bound)
131 134
     max_temp = int(TMAX if TMAX < up_bound else up_bound)
132
-    temps = range(max_temp, TMIN+step, step);
135
+    temps = list(range(max_temp, TMIN+step, step));
133 136
 
134
-    print "// Thermistor lookup table for Marlin"
135
-    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)
136
-    print "// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3)
137
-    print "// Theoretical limits of thermistor: %.2f to %.2f degC" % (low_bound, up_bound)
138
-    print
139
-    print "const short temptable[][2] PROGMEM = {"
137
+    print("// Thermistor lookup table for Marlin")
138
+    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))
139
+    print("// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3))
140
+    print("// Theoretical limits of thermistor: %.2f to %.2f degC" % (low_bound, up_bound))
141
+    print()
142
+    print("const short temptable[][2] PROGMEM = {")
140 143
 
141 144
     for temp in temps:
142 145
         adc = t.adc(temp)
143
-        print "    { OV(%7.2f), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \
146
+        print("    { OV(%7.2f), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \
144 147
                         ',' if temp != temps[-1] else ' ', \
145 148
                         t.voltage(adc), \
146 149
                         t.resist( adc), \
147 150
                         t.resol(  adc) \
148
-                    )
149
-    print "};"
151
+                    ))
152
+    print("};")
150 153
 
151 154
 def usage():
152
-    print __doc__
155
+    print(__doc__)
153 156
 
154 157
 if __name__ == "__main__":
155 158
     main(sys.argv[1:])

+ 3
- 1
buildroot/share/scripts/g29_auto.py Dosyayı Görüntüle

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

Loading…
İptal
Kaydet