Skip to content

Commit e492dca

Browse files
Minor refactor, only write out file if it changed
1 parent 581c921 commit e492dca

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

OATFWGUI/gui_logic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ def patch_line(in_str: str) -> str:
263263
patch_line(line)
264264
for line in ini_lines
265265
]
266-
with open(Path(self.logic_state.fw_dir, 'platformio.ini').resolve(), 'w') as fp:
267-
fp.writelines(ini_lines)
268266

269267
if self.logic_state.env_is_avr_based():
270268
# hard match the entire line
@@ -279,8 +277,6 @@ def patch_line(in_str: str) -> str:
279277
good_platform_line if line == bad_platform_line else line
280278
for line in ini_lines
281279
]
282-
with open(Path(self.logic_state.fw_dir, 'platformio.ini').resolve(), 'w') as fp:
283-
fp.writelines(ini_lines)
284280

285281
bad_ssd_1306_revision_re = re.compile(r'(ClutchplateDude/esp8266-oled-ssd1306\s*#\s*4\.6\.0)')
286282
if any(bad_ssd_1306_revision_re.search(ini_line) for ini_line in ini_lines):
@@ -296,8 +292,14 @@ def patch_line(in_str: str) -> str:
296292
patch_line(line)
297293
for line in ini_lines
298294
]
295+
296+
# Just re-read the ini file to see if we changed anything
297+
if ini_lines != read_platformio_ini_file(self.logic_state):
298+
log.debug('Writing out patched ini file')
299299
with open(Path(self.logic_state.fw_dir, 'platformio.ini').resolve(), 'w') as fp:
300300
fp.writelines(ini_lines)
301+
else:
302+
log.debug('No patches applied')
301303

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

0 commit comments

Comments
 (0)