From f2a5800cea0d87952af1a3e079eea9b3a7aaf43c Mon Sep 17 00:00:00 2001 From: Kurt Haenen Date: Mon, 20 Jun 2022 18:10:57 +0200 Subject: configfile: Expose options awaiting to be saved (#5270) Adds a save_config_pending_items to the status reported by configfile reflecting the items and values that a future SAVE_CONFIG would actually persist. Signed-off-by: Kurt Haenen --- klippy/configfile.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'klippy/configfile.py') diff --git a/klippy/configfile.py b/klippy/configfile.py index 165e9320..63dd8149 100644 --- a/klippy/configfile.py +++ b/klippy/configfile.py @@ -140,6 +140,7 @@ class PrinterConfig: self.autosave = None self.deprecated = {} self.status_raw_config = {} + self.status_save_pending = {} self.status_settings = {} self.status_warnings = [] self.save_config_pending = False @@ -331,18 +332,36 @@ class PrinterConfig: return {'config': self.status_raw_config, 'settings': self.status_settings, 'warnings': self.status_warnings, - 'save_config_pending': self.save_config_pending} + 'save_config_pending': self.save_config_pending, + 'save_config_pending_items': self.status_save_pending} # Autosave functions def set(self, section, option, value): if not self.autosave.fileconfig.has_section(section): self.autosave.fileconfig.add_section(section) svalue = str(value) self.autosave.fileconfig.set(section, option, svalue) + pending = dict(self.status_save_pending) + if not section in pending or pending[section] is None: + pending[section] = {} + else: + pending[section] = dict(pending[section]) + pending[section][option] = svalue + self.status_save_pending = pending self.save_config_pending = True logging.info("save_config: set [%s] %s = %s", section, option, svalue) def remove_section(self, section): - self.autosave.fileconfig.remove_section(section) - self.save_config_pending = True + if self.autosave.fileconfig.has_section(section): + self.autosave.fileconfig.remove_section(section) + pending = dict(self.status_save_pending) + pending[section] = None + self.status_save_pending = pending + self.save_config_pending = True + elif (section in self.status_save_pending and + self.status_save_pending[section] is not None): + pending = dict(self.status_save_pending) + del pending[section] + self.status_save_pending = pending + self.save_config_pending = True def _disallow_include_conflicts(self, regular_data, cfgname, gcode): config = self._build_config_wrapper(regular_data, cfgname) for section in self.autosave.fileconfig.sections(): -- cgit v1.2.3-70-g09d2