123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287 |
- from __future__ import print_function
- from __future__ import division
- import sys,os,re
- pwd = os.getcwd()
- pwd = pwd.replace('\\', '/')
- if 0 <= pwd.find('buildroot/share/vscode'):
- pwd = pwd[:pwd.find('buildroot/share/vscode')]
- os.chdir(pwd)
- print('pwd: ', pwd)
- num_args = len(sys.argv)
- if num_args > 1:
- build_type = str(sys.argv[1])
- else:
- print('Please specify build type')
- exit()
- print('build_type: ', build_type)
- print('\nWorking\n')
- python_ver = sys.version_info[0]
- print("python version " + str(sys.version_info[0]) + "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]))
- import platform
- current_OS = platform.system()
- target_env = ''
- board_name = ''
- from datetime import datetime, date, time
- def get_answer(board_name, question_txt, options, default_value=1):
- if python_ver == 2:
- import Tkinter as tk
- else:
- import tkinter as tk
- def CPU_exit_3():
- CPU_exit_3_()
- def got_answer():
- got_answer_()
- def kill_session():
- kill_session_()
- root_get_answer = tk.Tk()
- root_get_answer.title('')
-
-
- root_get_answer.attributes("-topmost", True)
- def disable_event():
- pass
- root_get_answer.protocol("WM_DELETE_WINDOW", disable_event)
- root_get_answer.resizable(False, False)
- root_get_answer.radio_state = default_value
- global get_answer_val
- get_answer_val = default_value
- radio_state = tk.IntVar()
- radio_state.set(get_answer_val)
- l1 = tk.Label(text=board_name, fg="light green", bg="dark green",
- font="default 14 bold").grid(row=0, columnspan=2, sticky='EW', ipadx=2, ipady=2)
- l2 = tk.Label(text=question_txt).grid(row=1, pady=4, columnspan=2, sticky='EW')
- buttons = []
- for index, val in enumerate(options):
- buttons.append(
- tk.Radiobutton(
- text=val,
- fg="black",
- bg="lightgray",
- relief=tk.SUNKEN,
- selectcolor="green",
- variable=radio_state,
- value=index + 1,
- indicatoron=0,
- command=CPU_exit_3
- ).grid(row=index + 2, pady=1, ipady=2, ipadx=10, columnspan=2))
- b6 = tk.Button(text="Cancel", fg="red", command=kill_session).grid(row=(2 + len(options)), column=0, padx=4, pady=4, ipadx=2, ipady=2)
- b7 = tk.Button(text="Continue", fg="green", command=got_answer).grid(row=(2 + len(options)), column=1, padx=4, pady=4, ipadx=2, ipady=2)
- def got_answer_():
- root_get_answer.destroy()
- def CPU_exit_3_():
- global get_answer_val
- get_answer_val = radio_state.get()
- def kill_session_():
- raise SystemExit(0)
- root_get_answer.mainloop()
- def resolve_path(path):
- import os
-
- if 0 <= path.find('"'):
- path = path[path.find('"'):]
- if 0 <= path.find(', line '):
- path = path.replace(', line ', ':')
- path = path.replace('"', '')
-
- line_num = 1
- column_num = 1
- line_start = path.find(':', 2)
- column_start = path.find(':', line_start + 1)
- if column_start == -1:
- column_start = len(path)
- column_end = path.find(':', column_start + 1)
- if column_end == -1:
- column_end = len(path)
- if 0 <= line_start:
- line_num = path[line_start + 1:column_start]
- if line_num == '':
- line_num = 1
- if column_start != column_end:
- column_num = path[column_start + 1:column_end]
- if column_num == '':
- column_num = 0
- index_end = path.find(',')
- if 0 <= index_end:
- path = path[:index_end]
- index_end = path.find(':', 2)
- if 0 <= index_end:
- path = path[:path.find(':', 2)]
- path = path.replace('\\', '/')
- if 1 == path.find(':') and current_OS == 'Windows':
- return path, line_num, column_num
- elif 0 == path.find('/') and (current_OS == 'Linux' or current_OS == 'Darwin'):
- return path, line_num, column_num
- else:
-
- while 0 <= path.find('../'):
- end = path.find('../') - 1
- start = path.find('/')
- while 0 <= path.find('/', start) < end:
- start = path.find('/', start) + 1
- path = path[0:start] + path[end + 4:]
-
-
-
-
-
-
-
- start = path.find('/')
- if start != 0:
- while 0 == path.find(' '):
- path = path[1:]
- path = '/' + path
- if current_OS == 'Windows':
- search_path = path.replace('/', '\\')
- else:
- search_path = path
- start_path = os.path.abspath('')
-
- found = False
- full_path = ''
- for root, directories, filenames in os.walk(start_path):
- for filename in filenames:
- if 0 <= root.find('.git'):
- break
- full_path = os.path.join(root, filename)
- if 0 <= full_path.find(search_path):
- found = True
- break
- if found:
- break
- return full_path, line_num, column_num
- def open_file(path):
- import subprocess
- file_path, line_num, column_num = resolve_path(path)
- if file_path == '':
- return
- if current_OS == 'Windows':
- editor_note = subprocess.check_output('wmic process where "name=' + "'notepad++.exe'" + '" get ExecutablePath')
- editor_sublime = subprocess.check_output('wmic process where "name=' + "'sublime_text.exe'" + '" get ExecutablePath')
- editor_atom = subprocess.check_output('wmic process where "name=' + "'atom.exe'" + '" get ExecutablePath')
- if 0 <= editor_note.find('notepad++.exe'):
- start = editor_note.find('\n') + 1
- end = editor_note.find('\n', start + 5) - 4
- editor_note = editor_note[start:end]
- command = file_path, ' -n' + str(line_num), ' -c' + str(column_num)
- subprocess.Popen([editor_note, command])
- elif 0 <= editor_sublime.find('sublime_text.exe'):
- start = editor_sublime.find('\n') + 1
- end = editor_sublime.find('\n', start + 5) - 4
- editor_sublime = editor_sublime[start:end]
- command = file_path + ':' + line_num + ':' + column_num
- subprocess.Popen([editor_sublime, command])
- elif 0 <= editor_atom.find('atom.exe'):
- start = editor_atom.find('\n') + 1
- end = editor_atom.find('\n', start + 5) - 4
- editor_atom = editor_atom[start:end]
- command = file_path + ':' + str(line_num) + ':' + str(column_num)
- subprocess.Popen([editor_atom, command])
- else:
- os.startfile(resolve_path(path))
- elif current_OS == 'Linux':
- command = file_path + ':' + str(line_num) + ':' + str(column_num)
- index_end = command.find(',')
- if 0 <= index_end:
- command = command[:index_end]
- running_apps = subprocess.Popen('ps ax -o cmd', stdout=subprocess.PIPE, shell=True)
- (output, err) = running_apps.communicate()
- temp = output.split('\n')
- def find_editor_linux(name, search_obj):
- for line in search_obj:
- if 0 <= line.find(name):
- path = line
- return True, path
- return False, ''
- (success_sublime, editor_path_sublime) = find_editor_linux('sublime_text', temp)
- (success_atom, editor_path_atom) = find_editor_linux('atom', temp)
- if success_sublime:
- subprocess.Popen([editor_path_sublime, command])
- elif success_atom:
- subprocess.Popen([editor_path_atom, command])
- else:
- os.system('xdg-open ' + file_path)
- elif current_OS == 'Darwin':
- command = file_path + ':' + str(line_num) + ':' + str(column_num)
- index_end = command.find(',')
- if 0 <= index_end:
- command = command[:index_end]
- running_apps = subprocess.Popen('ps axwww -o command', stdout=subprocess.PIPE, shell=True)
- (output, err) = running_apps.communicate()
- temp = output.split('\n')
- def find_editor_mac(name, search_obj):
- for line in search_obj:
- if 0 <= line.find(name):
- path = line
- if 0 <= path.find('-psn'):
- path = path[:path.find('-psn') - 1]
- return True, path
- return False, ''
- (success_sublime, editor_path_sublime) = find_editor_mac('Sublime', temp)
- (success_atom, editor_path_atom) = find_editor_mac('Atom', temp)
- if success_sublime:
- subprocess.Popen([editor_path_sublime, command])
- elif success_atom:
- subprocess.Popen([editor_path_atom, command])
- else:
- os.system('open ' + file_path)
- def get_build_last():
- env_last = ''
- DIR_PWD = os.listdir('.')
- if '.pio' in DIR_PWD:
- date_last = 0.0
- DIR__pioenvs = os.listdir('.pio')
- for name in DIR__pioenvs:
- if 0 <= name.find('.') or 0 <= name.find('-'):
- continue
- DIR_temp = os.listdir('.pio/build/' + name)
- for names_temp in DIR_temp:
- if 0 == names_temp.find('firmware.'):
- date_temp = os.path.getmtime('.pio/build/' + name + '/' + names_temp)
- if date_temp > date_last:
- date_last = date_temp
- env_last = name
- return env_last
- def get_board_name():
- board_name = ''
-
- with open('Marlin/Configuration.h', 'r') as myfile:
- Configuration_h = myfile.read()
- Configuration_h = Configuration_h.split('\n')
- Marlin_ver = 0
- for lines in Configuration_h:
- if 0 == lines.find('#define CONFIGURATION_H_VERSION 01'):
- Marlin_ver = 1
- if 0 == lines.find('#define CONFIGURATION_H_VERSION 02'):
- Marlin_ver = 2
- board = lines.find(' BOARD_') + 1
- motherboard = lines.find(' MOTHERBOARD ') + 1
- define = lines.find('#define ')
- comment = lines.find('//')
- if (comment == -1 or comment > board) and \
- board > motherboard and \
- motherboard > define and \
- define >= 0 :
- spaces = lines.find(' ', board)
- if spaces == -1:
- board_name = lines[board:]
- else:
- board_name = lines[board:spaces]
- break
- return board_name, Marlin_ver
- def get_env_from_line(line, start_position):
- env = ''
- next_position = -1
- env_position = line.find('env:', start_position)
- if 0 < env_position:
- next_position = line.find(' ', env_position + 4)
- if 0 < next_position:
- env = line[env_position + 4:next_position]
- else:
- env = line[env_position + 4:]
- return env, next_position
- def invalid_board():
- print('ERROR - invalid board')
- print(board_name)
- raise SystemExit(0)
- def get_starting_env(board_name_full, version):
-
- if version == 1:
- path = 'Marlin/pins.h'
- if version == 2:
- path = 'Marlin/src/pins/pins.h'
- with open(path, 'r') as myfile:
- pins_h = myfile.read()
- board_name = board_name_full[6:]
- pins_h = pins_h.split('\n')
- list_start_found = False
- possible_envs = None
- for i, line in enumerate(pins_h):
- if 0 < line.find("Unknown MOTHERBOARD value set in Configuration.h"):
- invalid_board();
- if list_start_found == False and 0 < line.find('1280'):
- list_start_found = True
- elif list_start_found == False:
- continue
-
-
-
- if re.search(r'MB.*[\(, ]' + board_name + r'[, \)]', line):
-
- possible_envs = re.findall(r'env:([^ ]+)', pins_h[i + 1])
- break
- return possible_envs
- def get_env(board_name, ver_Marlin):
- def no_environment():
- print('ERROR - no environment for this board')
- print(board_name)
- raise SystemExit(0)
- possible_envs = get_starting_env(board_name, ver_Marlin)
- if not possible_envs:
- no_environment()
-
-
-
-
- CPU_questions = [
- {'options':['1280', '2560'], 'text':'1280 or 2560 CPU?', 'default':2},
- {'options':['644', '1284'], 'text':'644 or 1284 CPU?', 'default':2},
- {'options':['STM32F103RC', 'STM32F103RE'], 'text':'MCU Type?', 'default':1}]
- for question in CPU_questions:
- if any(question['options'][0] in env for env in possible_envs) and any(question['options'][1] in env for env in possible_envs):
- get_answer(board_name, question['text'], [question['options'][0], question['options'][1]], question['default'])
- possible_envs = [env for env in possible_envs if question['options'][get_answer_val - 1] in env]
-
- if [env for env in possible_envs if '_maple' in env] and [env for env in possible_envs if '_maple' not in env]:
- get_answer(board_name, 'Which STM32 Framework should be used?', ['ST STM32 (Preferred)', 'Maple (Deprecated)'])
- if 1 == get_answer_val:
- possible_envs = [env for env in possible_envs if '_maple' not in env]
- else:
- possible_envs = [env for env in possible_envs if '_maple' in env]
-
- if any('STM32F103R' in env for env in possible_envs) and any('_USB' in env for env in possible_envs) and any('_USB' not in env for env in possible_envs):
- get_answer(board_name, 'USB Support?', ['USB', 'No USB'])
- if 1 == get_answer_val:
- possible_envs = [env for env in possible_envs if '_USB' in env]
- else:
- possible_envs = [env for env in possible_envs if '_USB' not in env]
- if not possible_envs:
- no_environment()
- if len(possible_envs) == 1:
- return possible_envs[0]
- target_env = None
-
- if 'LPC1768' in possible_envs:
- if build_type == 'traceback' or (build_type == 'clean' and get_build_last() == 'LPC1768_debug_and_upload'):
- target_env = 'LPC1768_debug_and_upload'
- else:
- target_env = 'LPC1768'
- elif 'DUE' in possible_envs:
- target_env = 'DUE'
- if build_type == 'traceback' or (build_type == 'clean' and get_build_last() == 'DUE_debug'):
- target_env = 'DUE_debug'
- elif 'DUE_USB' in possible_envs:
- get_answer(board_name, 'DUE Download Port?', ['(Native) USB port', 'Programming port'])
- if 1 == get_answer_val:
- target_env = 'DUE_USB'
- else:
- target_env = 'DUE'
- else:
- options = possible_envs
-
-
-
- for i, option in enumerate(options):
- if 'melzi' in option:
- options[i] = 'Melzi'
- elif 'sanguino1284p' in option:
- options[i] = 'sanguino1284p'
- if 'optiboot' in option:
- options[i] = options[i] + ' (Optiboot Bootloader)'
- if 'optimized' in option:
- options[i] = options[i] + ' (Optimized for Size)'
- get_answer(board_name, 'Which environment?', options)
- target_env = possible_envs[get_answer_val - 1]
- if build_type == 'traceback' and target_env != 'LPC1768_debug_and_upload' and target_env != 'DUE_debug' and Marlin_ver == 2:
- print("ERROR - this board isn't setup for traceback")
- print('board_name: ', board_name)
- print('target_env: ', target_env)
- raise SystemExit(0)
- return target_env
- if python_ver == 2:
- import Queue as queue
- else:
- import queue as queue
- IO_queue = queue.Queue()
- def write_to_screen_queue(text, format_tag='normal'):
- double_in = [text, format_tag]
- IO_queue.put(double_in, block=False)
- warning = False
- warning_FROM = False
- error = False
- standard = True
- prev_line_COM = False
- next_line_warning = False
- warning_continue = False
- line_counter = 0
- def line_print(line_input):
- global warning
- global warning_FROM
- global error
- global standard
- global prev_line_COM
- global next_line_warning
- global warning_continue
- global line_counter
-
- platformio_highlights = [
- ['Environment', 0, 'highlight_blue'], ['[SKIP]', 1, 'warning'], ['[IGNORED]', 1, 'warning'], ['[ERROR]', 1, 'error'],
- ['[FAILED]', 1, 'error'], ['[SUCCESS]', 1, 'highlight_green']
- ]
- def write_to_screen_with_replace(text, highlights):
- did_something = False
- for highlight in highlights:
- found = text.find(highlight[0])
- if did_something == True:
- break
- if found >= 0:
- did_something = True
- if 0 == highlight[1]:
- found_1 = text.find(' ')
- found_tab = text.find('\t')
- if not (0 <= found_1 <= found_tab):
- found_1 = found_tab
- write_to_screen_queue(text[:found_1 + 1])
- for highlight_2 in highlights:
- if highlight[0] == highlight_2[0]:
- continue
- found = text.find(highlight_2[0])
- if found >= 0:
- found_space = text.find(' ', found_1 + 1)
- found_tab = text.find('\t', found_1 + 1)
- if not (0 <= found_space <= found_tab):
- found_space = found_tab
- found_right = text.find(']', found + 1)
- write_to_screen_queue(text[found_1 + 1:found_space + 1], highlight[2])
- write_to_screen_queue(text[found_space + 1:found + 1])
- write_to_screen_queue(text[found + 1:found_right], highlight_2[2])
- write_to_screen_queue(text[found_right:] + '\n')
- break
- break
- if 1 == highlight[1]:
- found_right = text.find(']', found + 1)
- write_to_screen_queue(text[:found + 1])
- write_to_screen_queue(text[found + 1:found_right], highlight[2])
- write_to_screen_queue(text[found_right:] + '\n' + '\n')
- break
- if did_something == False:
- r_loc = text.find('\r') + 1
- if 0 < r_loc < len(text):
- text = text.split('\r')
- for line in text:
- if line != '':
- write_to_screen_queue(line + '\n')
- else:
- write_to_screen_queue(text + '\n')
-
- line_counter = line_counter + 1
- max_search = len(line_input)
- if max_search > 3:
- max_search = 3
- beginning = line_input[:max_search]
-
- if 0 < line_input.find(': warning: '):
- warning = True
- warning_FROM = False
- error = False
- standard = False
- prev_line_COM = False
- prev_line_COM = False
- warning_continue = True
- if 0 < line_input.find('Thank you') or 0 < line_input.find('SUMMARY'):
- warning = False
- warning_FROM = False
- error = False
- standard = True
- prev_line_COM = False
- warning_continue = False
- elif beginning == 'War' or \
- beginning == '#er' or \
- beginning == 'In ' or \
- (beginning != 'Com' and prev_line_COM == True and not(beginning == 'Arc' or beginning == 'Lin' or beginning == 'Ind') or \
- next_line_warning == True):
- warning = True
- warning_FROM = False
- error = False
- standard = False
- prev_line_COM = False
- elif beginning == 'Com' or \
- beginning == 'Ver' or \
- beginning == ' [E' or \
- beginning == 'Rem' or \
- beginning == 'Bui' or \
- beginning == 'Ind' or \
- beginning == 'PLA':
- warning = False
- warning_FROM = False
- error = False
- standard = True
- prev_line_COM = False
- warning_continue = False
- elif beginning == '***':
- warning = False
- warning_FROM = False
- error = True
- standard = False
- prev_line_COM = False
- elif 0 < line_input.find(': error:') or \
- 0 < line_input.find(': fatal error:'):
- warning = False
- warning_FROM = False
- error = True
- standard = False
- prev_line_COM = False
- warning_continue = True
- elif beginning == 'fro' and warning == True or \
- beginning == '.pi' :
- warning_FROM = True
- prev_line_COM = False
- warning_continue = True
- elif warning_continue == True:
- warning = True
- warning_FROM = False
- error = False
- standard = False
- prev_line_COM = False
- warning_continue = True
- else:
- warning = False
- warning_FROM = False
- error = False
- standard = True
- prev_line_COM = False
- warning_continue = False
- if beginning == 'Com':
- prev_line_COM = True
- if standard == True:
- write_to_screen_with_replace(line_input, platformio_highlights)
- if warning == True:
- write_to_screen_queue(line_input + '\n', 'warning')
- if error == True:
- write_to_screen_queue(line_input + '\n', 'error')
- def sys_PIO():
-
-
-
-
-
- global build_type
- global target_env
- import os
- print('build_type: ', build_type)
- print('starting platformio')
- if build_type == 'build':
-
- pio_result = os.system('platformio run -e ' + target_env)
- elif build_type == 'clean':
- pio_result = os.system('platformio run --target clean -e ' + target_env)
- elif build_type == 'upload':
- pio_result = os.system('platformio run --target upload -e ' + target_env)
- elif build_type == 'traceback':
- pio_result = os.system('platformio run --target upload -e ' + target_env)
- elif build_type == 'program':
- pio_result = os.system('platformio run --target program -e ' + target_env)
- elif build_type == 'test':
- pio_result = os.system('platformio test upload -e ' + target_env)
- elif build_type == 'remote':
- pio_result = os.system('platformio remote run --target program -e ' + target_env)
- elif build_type == 'debug':
- pio_result = os.system('platformio debug -e ' + target_env)
- else:
- print('ERROR - unknown build type: ', build_type)
- raise SystemExit(0)
-
-
-
-
-
-
-
-
- def run_PIO(dummy):
- global build_type
- global target_env
- global board_name
- print('build_type: ', build_type)
- import subprocess
- import sys
- print('starting platformio')
- if build_type == 'build':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'run', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- elif build_type == 'clean':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'run', '--target', 'clean', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- elif build_type == 'upload':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'run', '--target', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- elif build_type == 'traceback':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'run', '--target', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- elif build_type == 'program':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'run', '--target', 'program', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- elif build_type == 'test':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'test', 'upload', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- elif build_type == 'remote':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'remote', 'run', '--target', 'program', '-e', target_env],
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT
- )
- elif build_type == 'debug':
-
-
- pio_subprocess = subprocess.Popen(
- ['platformio', 'debug', '-e', target_env], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- else:
- print('ERROR - unknown build type: ', build_type)
- raise SystemExit(0)
- 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', ''))
- write_to_screen_queue('\nBoard name: ' + board_name + '\n')
- write_to_screen_queue('Build type: ' + build_type + '\n')
- write_to_screen_queue('Environment used: ' + target_env + '\n')
- write_to_screen_queue(str(datetime.now()) + '\n')
- import time
- import threading
- if python_ver == 2:
- import Tkinter as tk
- import Queue as queue
- import ttk
- from Tkinter import Tk, Frame, Text, Scrollbar, Menu
-
- import tkFileDialog as fileDialog
- else:
- import tkinter as tk
- import queue as queue
- from tkinter import ttk, Tk, Frame, Text, Menu
- import subprocess
- import sys
- que = queue.Queue()
- class output_window(Text):
-
- global continue_updates
- continue_updates = True
- global search_position
- search_position = ''
- global error_found
- error_found = False
- def __init__(self):
- self.root = tk.Tk()
- self.root.attributes("-topmost", True)
- self.frame = tk.Frame(self.root)
- self.frame.pack(fill='both', expand=True)
-
-
- Text.__init__(self, self.frame, borderwidth=3, relief="sunken")
- self.config(tabs=(400, ))
- self.config(background='black', foreground='white', font=("consolas", 12), wrap='word', undo='True')
-
- self.config(height=24, width=100)
- self.config(insertbackground='pale green')
- self.pack(side='left', fill='both', expand=True)
- self.tag_config('normal', foreground='white')
- self.tag_config('warning', foreground='yellow')
- self.tag_config('error', foreground='red')
- self.tag_config('highlight_green', foreground='green')
- self.tag_config('highlight_blue', foreground='cyan')
- self.tag_config('error_highlight_inactive', background='dim gray')
- self.tag_config('error_highlight_active', background='light grey')
- self.bind_class("Text", "<Control-a>", self.select_all)
- self.bind_all("<Control-Shift-E>", self.scroll_errors)
- self.bind_class("<Control-Shift-R>", self.rebuild)
-
- scrb = tk.Scrollbar(self.frame, orient='vertical', command=self.yview)
- self.config(yscrollcommand=scrb.set)
- scrb.pack(side='right', fill='y')
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- self.popup = tk.Menu(self, tearoff=0)
- self.popup.add_command(label='Copy', command=self._copy)
- self.popup.add_command(label='Paste', command=self._paste)
- self.popup.add_separator()
- self.popup.add_command(label='Cut', command=self._cut)
- self.popup.add_separator()
- self.popup.add_command(label='Select All', command=self._select_all)
- self.popup.add_command(label='Clear All', command=self._clear_all)
- self.popup.add_separator()
- self.popup.add_command(label='Save As', command=self._file_save_as)
- self.popup.add_separator()
-
- self.popup.add_command(label='Repeat Build', command=self._rebuild)
- self.popup.add_separator()
- self.popup.add_command(label='Scroll Errors (CTL-shift-e)', command=self._scroll_errors)
- self.popup.add_separator()
- self.popup.add_command(label='Open File at Cursor', command=self._open_selected_file)
- if current_OS == 'Darwin':
- self.bind('<Button-2>', self._show_popup)
- else:
- self.bind('<Button-3>', self._show_popup)
- def start_thread(self, ):
- global continue_updates
-
-
- self.secondary_thread = threading.Thread(target=lambda q, arg1: q.put(run_PIO(arg1)), args=(que, ''))
- self.secondary_thread.start()
- continue_updates = True
-
- self.root.after(50, self.check_thread)
- self.root.after(50, self.update)
- def check_thread(self):
- global continue_updates
- if continue_updates == True:
- self.root.after(10, self.check_thread)
- def update(self):
- global continue_updates
- if continue_updates == True:
- self.root.after(10, self.update)
- temp_text = ['0', '0']
- if IO_queue.empty():
- if not (self.secondary_thread.is_alive()):
- continue_updates = False
- else:
- try:
- temp_text = IO_queue.get(block=False)
- except Queue.Empty:
- continue_updates = False
- else:
- self.insert('end', temp_text[0], temp_text[1])
- self.see("end")
- def _scroll_errors(self):
- global search_position
- global error_found
- if search_position == '':
- countVar = tk.IntVar()
- search_position = '1.0'
- search_count = 0
- while search_position != '' and search_count < 100:
- search_position = self.search("error", search_position, stopindex="end", count=countVar, nocase=1)
- search_count = search_count + 1
- if search_position != '':
- error_found = True
- end_pos = '{}+{}c'.format(search_position, 5)
- self.tag_add("error_highlight_inactive", search_position, end_pos)
- search_position = '{}+{}c'.format(search_position, 1)
- else:
- break
- if error_found:
- if search_position == '':
- search_position = self.search("error", '1.0', stopindex="end", nocase=1)
- else:
- end_pos = '{}+{}c'.format(search_position, 5)
- start_pos = '{}+{}c'.format(search_position, -1)
- self.tag_remove("error_highlight_active", start_pos, end_pos)
- search_position = self.search(
- "error", search_position, stopindex="end", nocase=1
- )
- if search_position == "":
- search_position = self.search("error", '1.0', stopindex="end", nocase=1)
- end_pos = '{}+{}c'.format(search_position, 5)
- self.tag_add("error_highlight_active", search_position, end_pos)
- self.see(search_position)
- search_position = '{}+{}c'.format(search_position, 1)
- def scroll_errors(self, event):
- self._scroll_errors()
- def _rebuild(self):
-
-
-
-
-
- self.start_thread()
- def rebuild(self, event):
- print("event happened")
- self._rebuild()
- def _open_selected_file(self):
- current_line = self.index('insert')
- line_start = current_line[:current_line.find('.')] + '.0'
- line_end = current_line[:current_line.find('.')] + '.200'
- self.mark_set("path_start", line_start)
- self.mark_set("path_end", line_end)
- path = self.get("path_start", "path_end")
- from_loc = path.find('from ')
- colon_loc = path.find(': ')
- if 0 <= from_loc and ((colon_loc == -1) or (from_loc < colon_loc)):
- path = path[from_loc + 5:]
- if 0 <= colon_loc:
- path = path[:colon_loc]
- if 0 <= path.find('\\') or 0 <= path.find('/'):
- open_file(path)
- def _file_save_as(self):
- self.filename = fileDialog.asksaveasfilename(defaultextension='.txt')
- f = open(self.filename, 'w')
- f.write(self.get('1.0', 'end'))
- f.close()
- def copy(self, event):
- try:
- selection = self.get(*self.tag_ranges('sel'))
- self.clipboard_clear()
- self.clipboard_append(selection)
- except TypeError:
- pass
- def cut(self, event):
- try:
- selection = self.get(*self.tag_ranges('sel'))
- self.clipboard_clear()
- self.clipboard_append(selection)
- self.delete(*self.tag_ranges('sel'))
- except TypeError:
- pass
- def _show_popup(self, event):
- '''right-click popup menu'''
- if self.root.focus_get() != self:
- self.root.focus_set()
- try:
- self.popup.tk_popup(event.x_root, event.y_root, 0)
- finally:
- self.popup.grab_release()
- def _cut(self):
- try:
- selection = self.get(*self.tag_ranges('sel'))
- self.clipboard_clear()
- self.clipboard_append(selection)
- self.delete(*self.tag_ranges('sel'))
- except TypeError:
- pass
- def cut(self, event):
- self._cut()
- def _copy(self):
- try:
- selection = self.get(*self.tag_ranges('sel'))
- self.clipboard_clear()
- self.clipboard_append(selection)
- except TypeError:
- pass
- def copy(self, event):
- self._copy()
- def _paste(self):
- self.insert('insert', self.selection_get(selection='CLIPBOARD'))
- def _select_all(self):
- self.tag_add('sel', '1.0', 'end')
- def select_all(self, event):
- self.tag_add('sel', '1.0', 'end')
- def _clear_all(self):
-
-
-
-
-
-
- self.delete('1.0', 'end')
- def main():
-
-
-
-
-
- global build_type
- global target_env
- global board_name
- board_name, Marlin_ver = get_board_name()
- target_env = get_env(board_name, Marlin_ver)
-
- if os.environ.get('PLATFORMIO_CALLER', '') == 'vscode':
- sys_PIO()
- else:
- auto_build = output_window()
- auto_build.start_thread()
- auto_build.root.mainloop()
- if __name__ == '__main__':
- main()
|