Browse Source

AutoBuild compatibility with Python3 (#15331)

Giuliano Zaro 5 years ago
parent
commit
4e5941fa57
1 changed files with 48 additions and 50 deletions
  1. 48
    50
      buildroot/share/atom/auto_build.py

+ 48
- 50
buildroot/share/atom/auto_build.py View File

95
 
95
 
96
 python_ver = sys.version_info[0] # major version - 2 or 3
96
 python_ver = sys.version_info[0] # major version - 2 or 3
97
 
97
 
98
-if python_ver == 2:
99
-  print("python version " + str(sys.version_info[0]) + "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
100
-else:
101
-  print("python version " + str(sys.version_info[0]))
102
-  print("This script only runs under python 2")
103
-  exit()
98
+print("python version " + str(sys.version_info[0]) + "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
104
 
99
 
105
 import platform
100
 import platform
106
 current_OS = platform.system()
101
 current_OS = platform.system()
135
 
130
 
136
 
131
 
137
         if python_ver == 2:
132
         if python_ver == 2:
138
-          import Tkinter as tk
133
+            import Tkinter as tk
139
         else:
134
         else:
140
-          import tkinter as tk
135
+            import tkinter as tk
141
 
136
 
142
         def CPU_exit_3():   # forward declare functions
137
         def CPU_exit_3():   # forward declare functions
143
 
138
 
615
 # end - get_env
610
 # end - get_env
616
 
611
 
617
 # puts screen text into queue so that the parent thread can fetch the data from this thread
612
 # puts screen text into queue so that the parent thread can fetch the data from this thread
618
-import Queue
619
-IO_queue = Queue.Queue()
620
-PIO_queue = Queue.Queue()
613
+if python_ver == 2:
614
+    import Queue as queue
615
+else:
616
+    import queue as queue
617
+IO_queue = queue.Queue()
618
+#PIO_queue = queue.Queue()    not used!
621
 def write_to_screen_queue(text, format_tag = 'normal'):
619
 def write_to_screen_queue(text, format_tag = 'normal'):
622
       double_in = [text, format_tag]
620
       double_in = [text, format_tag]
623
       IO_queue.put(double_in, block = False)
621
       IO_queue.put(double_in, block = False)
940
           raise SystemExit(0)     # kill everything
938
           raise SystemExit(0)     # kill everything
941
 
939
 
942
   # stream output from subprocess and split it into lines
940
   # stream output from subprocess and split it into lines
943
-    for line in iter(pio_subprocess.stdout.readline, ''):
944
-          line_print(line.replace('\n', ''))
945
-
941
+    if python_ver == 2:
942
+        for line in iter(pio_subprocess.stdout.readline, ''):
943
+            line_print(line.replace('\n', ''))
944
+    else:
945
+        for line in iter(pio_subprocess.stdout.readline, b''):
946
+            line = line.decode('utf-8')
947
+            line_print(line.replace('\n', ''))
946
 
948
 
947
   # append info used to run PlatformIO
949
   # append info used to run PlatformIO
948
     write_to_screen_queue('\nBoard name: ' + board_name  + '\n')  # put build info at the bottom of the screen
950
     write_to_screen_queue('\nBoard name: ' + board_name  + '\n')  # put build info at the bottom of the screen
958
 
960
 
959
 import time
961
 import time
960
 import threading
962
 import threading
961
-import Tkinter as tk
962
-import ttk
963
-import Queue
963
+if python_ver == 2:
964
+    import Tkinter as tk
965
+    import Queue as queue
966
+    import ttk
967
+    from Tkinter import Tk, Frame, Text, Scrollbar, Menu
968
+    #from tkMessageBox import askokcancel      this is not used: removed
969
+    import tkFileDialog as fileDialog
970
+else:
971
+    import tkinter as tk
972
+    import queue as queue
973
+    from tkinter import ttk, Tk, Frame, Text, Scrollbar, Menu
974
+    from tkinter import filedialog
964
 import subprocess
975
 import subprocess
965
 import sys
976
 import sys
966
-que = Queue.Queue()
967
-#IO_queue = Queue.Queue()
968
-
969
-from Tkinter import Tk, Frame, Text, Scrollbar, Menu
970
-from tkMessageBox import askokcancel
971
-
972
-import tkFileDialog
973
-from tkMessageBox import askokcancel
974
-import tkFileDialog
975
-
977
+que = queue.Queue()
978
+#IO_queue = queue.Queue()
976
 
979
 
977
 class output_window(Text):
980
 class output_window(Text):
978
  # based on Super Text
981
  # based on Super Text
1177
 
1180
 
1178
 
1181
 
1179
     def _file_save_as(self):
1182
     def _file_save_as(self):
1180
-        self.filename = tkFileDialog.asksaveasfilename(defaultextension = '.txt')
1183
+        self.filename = fileDialog.asksaveasfilename(defaultextension = '.txt')
1181
         f = open(self.filename, 'w')
1184
         f = open(self.filename, 'w')
1182
         f.write(self.get('1.0', 'end'))
1185
         f.write(self.get('1.0', 'end'))
1183
         f.close()
1186
         f.close()
1267
 def main():
1270
 def main():
1268
 
1271
 
1269
 
1272
 
1270
-  ##########################################################################
1271
-  #                                                                        #
1272
-  # main program                                                           #
1273
-  #                                                                        #
1274
-  ##########################################################################
1275
-
1276
-        global build_type
1277
-        global target_env
1278
-        global board_name
1279
-
1280
-        board_name, Marlin_ver = get_board_name()
1273
+    ##########################################################################
1274
+    #                                                                        #
1275
+    # main program                                                           #
1276
+    #                                                                        #
1277
+    ##########################################################################
1281
 
1278
 
1282
-        target_env = get_env(board_name, Marlin_ver)
1279
+    global build_type
1280
+    global target_env
1281
+    global board_name
1283
 
1282
 
1284
-        os.environ["BUILD_TYPE"] = build_type   # let sub processes know what is happening
1285
-        os.environ["TARGET_ENV"] = target_env
1286
-        os.environ["BOARD_NAME"] = board_name
1283
+    board_name, Marlin_ver = get_board_name()
1287
 
1284
 
1288
-        # Re-use the VSCode terminal, if possible
1289
-        if os.environ.get('PLATFORMIO_CALLER', '') == 'vscode':
1290
-            sys_PIO()
1291
-        else:
1292
-           auto_build = output_window()
1293
-           auto_build.start_thread()  # executes the "run_PIO" function
1285
+    target_env = get_env(board_name, Marlin_ver)
1294
 
1286
 
1295
-           auto_build.root.mainloop()
1287
+    # Re-use the VSCode terminal, if possible
1288
+    if os.environ.get('PLATFORMIO_CALLER', '') == 'vscode':
1289
+        sys_PIO()
1290
+    else:
1291
+        auto_build = output_window()
1292
+        auto_build.start_thread()  # executes the "run_PIO" function
1296
 
1293
 
1294
+        auto_build.root.mainloop()
1297
 
1295
 
1298
 
1296
 
1299
 
1297
 

Loading…
Cancel
Save