From 6de4d54f4921525e00e227c145564d5de5cf75ce Mon Sep 17 00:00:00 2001 From: John Thornton Date: Sat, 31 Dec 2022 06:48:03 -0600 Subject: [PATCH] stop updateini from deleting a key that starts with pwm fixes #70 Signed-off-by: John Thornton --- mesact/src/libmesact/updateini.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/mesact/src/libmesact/updateini.py b/mesact/src/libmesact/updateini.py index 088b363..e86aa59 100644 --- a/mesact/src/libmesact/updateini.py +++ b/mesact/src/libmesact/updateini.py @@ -12,7 +12,6 @@ def update(self, parent, iniFile): self.iniFile = iniFile with open(self.iniFile,'r') as file: self.content = file.readlines() # create a list of the ini file - print(len(self.content)) self.get_sections() if self.content[0].startswith('# This file'): self.content[0] = ('# This file was updated with the Mesa Configuration' @@ -372,8 +371,7 @@ def update(self, parent, iniFile): self.get_sections() # update section start/end self.update_key(f'SPINDLE_0', 'SPINDLE_TYPE', parent.spindleTypeCB.currentData()) - - if parent.spindlePwmTypeCB.currentData(): + if parent.spindlePwmTypeCB.currentText() != 'Select': self.update_key(f'SPINDLE_0', 'SPINDLE_PWM_TYPE', parent.spindlePwmTypeCB.currentData()) self.update_key(f'SPINDLE_0', 'PWM_FREQUENCY', parent.pwmFrequencySB.value()) @@ -556,12 +554,8 @@ def get_sections(self): if previous: self.sections[previous][1] = value[0] - 1 previous = key - #for key, value in self.sections.items(): - # print(f'{key} {value}') def update_key(self, section, key, value): - #if section == 'SPINDLE_0': - # print(f'{section} {key} {value}') found = False start = self.sections[f'[{section}]'][0] end = self.sections[f'[{section}]'][1] @@ -574,25 +568,15 @@ def update_key(self, section, key, value): else: found = False if not found: - #print(self.sections) - #print(f'{end} {key} = {value} {len(self.sections)}') - print(len(self.content)) + print(f'{section} {key} {value}') self.content.insert(end, f'{key} = {value}\n') - print(len(self.content)) - #print(f'{end} {key} = {value} {len(self.sections)}') - print(f'{self.content[end]}') self.get_sections() # update section start/end - #print(self.sections) - s = self.sections[f'[{section}]'][0] - e = self.sections[f'[{section}]'][1] - #for item in self.content[start:end]: - # print(item) def delete_key(self, section, key): start = self.sections[f'[{section}]'][0] end = self.sections[f'[{section}]'][1] for item in self.content[start:end]: - if item.startswith(key): + if item.split('=')[0].strip() == key: index = self.content.index(item) del self.content[index] self.get_sections() # update section start/end