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,12 +95,7 @@ print('\nWorking\n')
95 95
 
96 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 100
 import platform
106 101
 current_OS = platform.system()
@@ -135,9 +130,9 @@ def get_answer(board_name, cpu_label_txt, cpu_a_txt, cpu_b_txt):
135 130
 
136 131
 
137 132
         if python_ver == 2:
138
-          import Tkinter as tk
133
+            import Tkinter as tk
139 134
         else:
140
-          import tkinter as tk
135
+            import tkinter as tk
141 136
 
142 137
         def CPU_exit_3():   # forward declare functions
143 138
 
@@ -615,9 +610,12 @@ def get_env(board_name, ver_Marlin):
615 610
 # end - get_env
616 611
 
617 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 619
 def write_to_screen_queue(text, format_tag = 'normal'):
622 620
       double_in = [text, format_tag]
623 621
       IO_queue.put(double_in, block = False)
@@ -940,9 +938,13 @@ def run_PIO(dummy):
940 938
           raise SystemExit(0)     # kill everything
941 939
 
942 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 949
   # append info used to run PlatformIO
948 950
     write_to_screen_queue('\nBoard name: ' + board_name  + '\n')  # put build info at the bottom of the screen
@@ -958,21 +960,22 @@ def run_PIO(dummy):
958 960
 
959 961
 import time
960 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 975
 import subprocess
965 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 980
 class output_window(Text):
978 981
  # based on Super Text
@@ -1177,7 +1180,7 @@ class output_window(Text):
1177 1180
 
1178 1181
 
1179 1182
     def _file_save_as(self):
1180
-        self.filename = tkFileDialog.asksaveasfilename(defaultextension = '.txt')
1183
+        self.filename = fileDialog.asksaveasfilename(defaultextension = '.txt')
1181 1184
         f = open(self.filename, 'w')
1182 1185
         f.write(self.get('1.0', 'end'))
1183 1186
         f.close()
@@ -1267,33 +1270,28 @@ class output_window(Text):
1267 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