Skip to content

Commit 7f0a53d

Browse files
Merge pull request #54 from OpenAstroTech/jswinoga/fix/53-deselect-when-fw-changed
Force FW re-download on version change, git tag hot patch
2 parents 8435efe + 1b6b4fd commit 7f0a53d

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

OATFWGUI/gui_logic.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(self, main_app: QWidget):
9595
self.logic_state = LogicState()
9696

9797
self.main_app = main_app
98+
main_app.wCombo_fw_version.currentIndexChanged.connect(self.fw_version_combo_box_changed)
9899
main_app.wBtn_download_fw.setEnabled(True)
99100
main_app.wBtn_download_fw.clicked.connect(self.spawn_worker_thread(self.download_and_extract_fw))
100101
main_app.wBtn_select_local_config.clicked.connect(self.open_local_config_file)
@@ -210,6 +211,20 @@ def download_and_extract_fw_result(main_app: 'MainWidget', pio_environments: Lis
210211
main_app.wCombo_pio_env.addItem(pio_env_name.nice_name)
211212
main_app.wCombo_pio_env.setPlaceholderText('Select Board')
212213

214+
@Slot()
215+
def fw_version_combo_box_changed(self, idx: int):
216+
if idx == self.logic_state.release_idx:
217+
return # Nothing changed, nothing to do
218+
# Clear most state, if FW version is changed we want the user to go through the steps again
219+
# (technically not necessary but can trip some users up)
220+
log.debug('FW version changed, clearing some state')
221+
self.logic_state.pio_envs.clear()
222+
self.logic_state.pio_env = None
223+
self.main_app.wSpn_download.setState(BusyIndicatorState.NONE)
224+
self.main_app.wCombo_pio_env.clear()
225+
self.main_app.wSpn_build.setState(BusyIndicatorState.NONE)
226+
self.worker_finished()
227+
213228
@Slot()
214229
def pio_env_combo_box_changed(self, idx: int):
215230
if self.logic_state.pio_envs and idx != -1:
@@ -229,12 +244,27 @@ def open_local_config_file(self):
229244
# manually update GUI
230245
self.worker_finished()
231246

232-
def build_fw(self):
233-
self.main_app.wSpn_build.setState(BusyIndicatorState.BUSY)
247+
def do_hot_patches(self):
248+
# Before logging anything, check that we need to do something
249+
ini_lines = read_platformio_ini_file(self.logic_state)
250+
bad_git_tag_re = re.compile(r'(github\.com.+)@')
251+
if any(bad_git_tag_re.search(ini_line) for ini_line in ini_lines):
252+
log.warning('Hot patching git tag specifiers!!!')
253+
def patch_line(in_str: str) -> str:
254+
if bad_git_tag_re.search(in_str):
255+
out_str = bad_git_tag_re.sub(r'\1#', in_str)
256+
log.warning(f'Replacing {in_str} with {out_str}')
257+
return out_str
258+
else:
259+
return in_str
260+
ini_lines = [
261+
patch_line(line)
262+
for line in ini_lines
263+
]
264+
with open(Path(self.logic_state.fw_dir, 'platformio.ini').resolve(), 'w') as fp:
265+
fp.writelines(ini_lines)
234266

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

283+
def build_fw(self):
284+
self.main_app.wSpn_build.setState(BusyIndicatorState.BUSY)
285+
286+
# Hot patches, since we can't re-release an old firmware tag
287+
self.do_hot_patches()
288+
253289
config_dest_path = str(Path(self.logic_state.fw_dir, 'Configuration_local.hpp').resolve())
254290
if Path(config_dest_path) != Path(self.logic_state.config_file_path):
255291
if QFile.exists(config_dest_path):

0 commit comments

Comments
 (0)