Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Klipper3d/klipper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Haenen <Misterke@users.noreply.github.com>2022-06-20 19:10:57 +0300
committerGitHub <noreply@github.com>2022-06-20 19:10:57 +0300
commitf2a5800cea0d87952af1a3e079eea9b3a7aaf43c (patch)
tree019b9e2691c2a3acef5b85b39c019b0a5a514a5f
parent6af931c4e1c5bf6f9590d0d6ad13d76e2594de77 (diff)
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 <kurt.haenen@gmail.com>
-rw-r--r--docs/Status_Reference.md2
-rw-r--r--klippy/configfile.py25
2 files changed, 24 insertions, 3 deletions
diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md
index a515901bf..4cc7512fd 100644
--- a/docs/Status_Reference.md
+++ b/docs/Status_Reference.md
@@ -41,6 +41,8 @@ The following information is available in the `configfile` object
here.) All values are returned as strings.
- `save_config_pending`: Returns true if there are updates that a
`SAVE_CONFIG` command may persist to disk.
+- `save_config_pending_items`: Contains the sections and options that
+ were changed and would be persisted by a `SAVE_CONFIG`.
- `warnings`: A list of warnings about config options. Each entry in
the list will be a dictionary containing a `type` and `message`
field (both strings). Additional fields may be available depending
diff --git a/klippy/configfile.py b/klippy/configfile.py
index 165e93202..63dd81496 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():