Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force FW re-download on version change, git tag hot patch #54

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions OATFWGUI/gui_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self, main_app: QWidget):
self.logic_state = LogicState()

self.main_app = main_app
main_app.wCombo_fw_version.currentIndexChanged.connect(self.fw_version_combo_box_changed)
main_app.wBtn_download_fw.setEnabled(True)
main_app.wBtn_download_fw.clicked.connect(self.spawn_worker_thread(self.download_and_extract_fw))
main_app.wBtn_select_local_config.clicked.connect(self.open_local_config_file)
Expand Down Expand Up @@ -210,6 +211,20 @@ def download_and_extract_fw_result(main_app: 'MainWidget', pio_environments: Lis
main_app.wCombo_pio_env.addItem(pio_env_name.nice_name)
main_app.wCombo_pio_env.setPlaceholderText('Select Board')

@Slot()
def fw_version_combo_box_changed(self, idx: int):
if idx == self.logic_state.release_idx:
return # Nothing changed, nothing to do
# Clear most state, if FW version is changed we want the user to go through the steps again
# (technically not necessary but can trip some users up)
log.debug('FW version changed, clearing some state')
self.logic_state.pio_envs.clear()
self.logic_state.pio_env = None
self.main_app.wSpn_download.setState(BusyIndicatorState.NONE)
self.main_app.wCombo_pio_env.clear()
self.main_app.wSpn_build.setState(BusyIndicatorState.NONE)
self.worker_finished()

@Slot()
def pio_env_combo_box_changed(self, idx: int):
if self.logic_state.pio_envs and idx != -1:
Expand All @@ -229,12 +244,27 @@ def open_local_config_file(self):
# manually update GUI
self.worker_finished()

def build_fw(self):
self.main_app.wSpn_build.setState(BusyIndicatorState.BUSY)
def do_hot_patches(self):
# Before logging anything, check that we need to do something
ini_lines = read_platformio_ini_file(self.logic_state)
bad_git_tag_re = re.compile(r'(github\.com.+)@')
if any(bad_git_tag_re.search(ini_line) for ini_line in ini_lines):
log.warning('Hot patching git tag specifiers!!!')
def patch_line(in_str: str) -> str:
if bad_git_tag_re.search(in_str):
out_str = bad_git_tag_re.sub(r'\1#', in_str)
log.warning(f'Replacing {in_str} with {out_str}')
return out_str
else:
return in_str
ini_lines = [
patch_line(line)
for line in ini_lines
]
with open(Path(self.logic_state.fw_dir, 'platformio.ini').resolve(), 'w') as fp:
fp.writelines(ini_lines)

if self.logic_state.env_is_avr_based():
# Before logging anything, check that we need to do something
ini_lines = read_platformio_ini_file(self.logic_state)
# hard match the entire line
# readline[s]() will always terminate a line with \n (and not \r\n on windows! :D)
# https://docs.python.org/3.11/tutorial/inputoutput.html#methods-of-file-objects
Expand All @@ -250,6 +280,12 @@ def build_fw(self):
with open(Path(self.logic_state.fw_dir, 'platformio.ini').resolve(), 'w') as fp:
fp.writelines(ini_lines)

def build_fw(self):
self.main_app.wSpn_build.setState(BusyIndicatorState.BUSY)

# Hot patches, since we can't re-release an old firmware tag
self.do_hot_patches()

config_dest_path = str(Path(self.logic_state.fw_dir, 'Configuration_local.hpp').resolve())
if Path(config_dest_path) != Path(self.logic_state.config_file_path):
if QFile.exists(config_dest_path):
Expand Down
Loading