Bladeren bron

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

Alexey Shvetsov 6 jaren geleden
bovenliggende
commit
af725c81e3

+ 9
- 5
buildroot/share/atom/create_custom_upload_command_CDC.py Bestand weergeven

1
+#!/usr/bin/env python
1
 #
2
 #
2
 #  Builds custom upload command
3
 #  Builds custom upload command
3
 #    1) Run platformio as a subprocess to find a COM port
4
 #    1) Run platformio as a subprocess to find a COM port
9
 #  Will continue on if a COM port isn't found so that the compilation can be done.
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
 import subprocess
16
 import subprocess
13
 import os
17
 import os
14
 import sys
18
 import sys
45
       global description_CDC
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
     # stream output from subprocess and split it into lines
54
     # stream output from subprocess and split it into lines
51
       pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
55
       pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
78
         com_CDC = com_CDC.replace('\r', '')
82
         com_CDC = com_CDC.replace('\r', '')
79
 
83
 
80
       if com_CDC == 'COM_PORT_NOT_FOUND':
84
       if com_CDC == 'COM_PORT_NOT_FOUND':
81
-          print com_CDC, '\n'
85
+          print(com_CDC, '\n')
82
       else:
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
   if current_OS == 'Windows':
90
   if current_OS == 'Windows':
87
 
91
 
114
 
118
 
115
 #      upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
119
 #      upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
116
       upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path  + ' -U flash:w:' + source_path + ':i'
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 Bestand weergeven

1
 #!/usr/bin/env python
1
 #!/usr/bin/env python
2
 
2
 
3
+from __future__ import print_function
4
+from __future__ import division
5
+
3
 """ Generate the stepper delay lookup table for Marlin firmware. """
6
 """ Generate the stepper delay lookup table for Marlin firmware. """
4
 
7
 
5
 import argparse
8
 import argparse
16
 cpu_freq = args.cpu_freq * 1000000
19
 cpu_freq = args.cpu_freq * 1000000
17
 timer_freq = cpu_freq / args.divider
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
 a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
29
 a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
27
 b = [ a[i] - a[i+1] for i in range(255) ]
30
 b = [ a[i] - a[i+1] for i in range(255) ]
28
 b.append(b[-1])
31
 b.append(b[-1])
29
 for i in range(32):
32
 for i in range(32):
30
-    print "  ",
33
+    print("  ", end=' ')
31
     for j in range(8):
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
 a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
41
 a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
39
 b = [ a[i] - a[i+1] for i in range(255) ]
42
 b = [ a[i] - a[i+1] for i in range(255) ]
40
 b.append(b[-1])
43
 b.append(b[-1])
41
 for i in range(32):
44
 for i in range(32):
42
-    print "  ",
45
+    print("  ", end=' ')
43
     for j in range(8):
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 Bestand weergeven

18
   --num-temps=...   the number of temperature points to calculate (default: 36)
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
 from math import *
24
 from math import *
22
 import sys
25
 import sys
23
 import getopt
26
 import getopt
47
         a = y1 - (b + l1**2 *c)*l1
50
         a = y1 - (b + l1**2 *c)*l1
48
 
51
 
49
         if c < 0:
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
             c = -c
56
             c = -c
54
         self.c1 = a                         # Steinhart-Hart coefficients
57
         self.c1 = a                         # Steinhart-Hart coefficients
55
         self.c2 = b
58
         self.c2 = b
97
     try:
100
     try:
98
         opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
101
         opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
99
     except getopt.GetoptError as err:
102
     except getopt.GetoptError as err:
100
-        print  str(err)
103
+        print(str(err))
101
         usage()
104
         usage()
102
         sys.exit(2)
105
         sys.exit(2)
103
 
106
 
129
     up_bound = t.temp(1);
132
     up_bound = t.temp(1);
130
     min_temp = int(TMIN if TMIN > low_bound else low_bound)
133
     min_temp = int(TMIN if TMIN > low_bound else low_bound)
131
     max_temp = int(TMAX if TMAX < up_bound else up_bound)
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
     for temp in temps:
144
     for temp in temps:
142
         adc = t.adc(temp)
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
                         ',' if temp != temps[-1] else ' ', \
147
                         ',' if temp != temps[-1] else ' ', \
145
                         t.voltage(adc), \
148
                         t.voltage(adc), \
146
                         t.resist( adc), \
149
                         t.resist( adc), \
147
                         t.resol(  adc) \
150
                         t.resol(  adc) \
148
-                    )
149
-    print "};"
151
+                    ))
152
+    print("};")
150
 
153
 
151
 def usage():
154
 def usage():
152
-    print __doc__
155
+    print(__doc__)
153
 
156
 
154
 if __name__ == "__main__":
157
 if __name__ == "__main__":
155
     main(sys.argv[1:])
158
     main(sys.argv[1:])

+ 3
- 1
buildroot/share/scripts/g29_auto.py Bestand weergeven

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

Laden…
Annuleren
Opslaan