AutoBuild compatibility with Python3 (#15331)

This commit is contained in:
Giuliano Zaro 2019-09-22 22:38:07 +02:00 committed by Scott Lahteine
parent 7fc4f7b815
commit 4e5941fa57

View File

@ -95,12 +95,7 @@ print('\nWorking\n')
python_ver = sys.version_info[0] # major version - 2 or 3
if python_ver == 2:
print("python version " + str(sys.version_info[0]) + "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
else:
print("python version " + str(sys.version_info[0]))
print("This script only runs under python 2")
exit()
import platform
current_OS = platform.system()
@ -615,9 +610,12 @@ def get_env(board_name, ver_Marlin):
# end - get_env
# puts screen text into queue so that the parent thread can fetch the data from this thread
import Queue
IO_queue = Queue.Queue()
PIO_queue = Queue.Queue()
if python_ver == 2:
import Queue as queue
else:
import queue as queue
IO_queue = queue.Queue()
#PIO_queue = queue.Queue() not used!
def write_to_screen_queue(text, format_tag = 'normal'):
double_in = [text, format_tag]
IO_queue.put(double_in, block = False)
@ -940,9 +938,13 @@ def run_PIO(dummy):
raise SystemExit(0) # kill everything
# stream output from subprocess and split it into lines
if python_ver == 2:
for line in iter(pio_subprocess.stdout.readline, ''):
line_print(line.replace('\n', ''))
else:
for line in iter(pio_subprocess.stdout.readline, b''):
line = line.decode('utf-8')
line_print(line.replace('\n', ''))
# append info used to run PlatformIO
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):
import time
import threading
if python_ver == 2:
import Tkinter as tk
import Queue as queue
import ttk
import Queue
from Tkinter import Tk, Frame, Text, Scrollbar, Menu
#from tkMessageBox import askokcancel this is not used: removed
import tkFileDialog as fileDialog
else:
import tkinter as tk
import queue as queue
from tkinter import ttk, Tk, Frame, Text, Scrollbar, Menu
from tkinter import filedialog
import subprocess
import sys
que = Queue.Queue()
#IO_queue = Queue.Queue()
from Tkinter import Tk, Frame, Text, Scrollbar, Menu
from tkMessageBox import askokcancel
import tkFileDialog
from tkMessageBox import askokcancel
import tkFileDialog
que = queue.Queue()
#IO_queue = queue.Queue()
class output_window(Text):
# based on Super Text
@ -1177,7 +1180,7 @@ class output_window(Text):
def _file_save_as(self):
self.filename = tkFileDialog.asksaveasfilename(defaultextension = '.txt')
self.filename = fileDialog.asksaveasfilename(defaultextension = '.txt')
f = open(self.filename, 'w')
f.write(self.get('1.0', 'end'))
f.close()
@ -1281,10 +1284,6 @@ def main():
target_env = get_env(board_name, Marlin_ver)
os.environ["BUILD_TYPE"] = build_type # let sub processes know what is happening
os.environ["TARGET_ENV"] = target_env
os.environ["BOARD_NAME"] = board_name
# Re-use the VSCode terminal, if possible
if os.environ.get('PLATFORMIO_CALLER', '') == 'vscode':
sys_PIO()
@ -1296,7 +1295,6 @@ def main():
if __name__ == '__main__':
main()