diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-09-04 14:20:24 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-09-16 13:44:54 -0400 |
commit | 46167cae672073b1ce0aeb4966b30c28bc47957e (patch) | |
tree | 52ea9318147b065b6848970e6821f7260e1f4190 /klippy/configfile.py | |
parent | c89db2480df57204d805f52c9c488e251bafe631 (diff) | |
download | kutter-46167cae672073b1ce0aeb4966b30c28bc47957e.tar.gz kutter-46167cae672073b1ce0aeb4966b30c28bc47957e.tar.xz kutter-46167cae672073b1ce0aeb4966b30c28bc47957e.zip |
configfile: Add support for reporting deprecated options
Add a new printer.configfile.warnings with a list of config features
that are deprecated.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/configfile.py')
-rw-r--r-- | klippy/configfile.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py index 7b4523ca..b6777d70 100644 --- a/klippy/configfile.py +++ b/klippy/configfile.py @@ -116,6 +116,17 @@ class ConfigWrapper: def get_prefix_options(self, prefix): return [o for o in self.fileconfig.options(self.section) if o.startswith(prefix)] + def deprecate(self, option, value=None): + if not self.fileconfig.has_option(self.section, option): + return + if value is None: + msg = ("Option '%s' in section '%s' is deprecated." + % (option, self.section)) + else: + msg = ("Value '%s' in option '%s' in section '%s' is deprecated." + % (value, option, self.section)) + pconfig = self.printer.lookup_object("configfile") + pconfig.deprecate(self.section, option, value, msg) AUTOSAVE_HEADER = """ #*# <---------------------- SAVE_CONFIG ----------------------> @@ -127,8 +138,10 @@ class PrinterConfig: def __init__(self, printer): self.printer = printer self.autosave = None + self.deprecated = {} self.status_raw_config = {} self.status_settings = {} + self.status_warnings = [] self.save_config_pending = False gcode = self.printer.lookup_object('gcode') gcode.register_command("SAVE_CONFIG", self.cmd_SAVE_CONFIG, @@ -289,6 +302,8 @@ class PrinterConfig: "======================="] self.printer.set_rollover_info("config", "\n".join(lines)) # Status reporting + def deprecate(self, section, option, value=None, msg=None): + self.deprecated[(section, option, value)] = msg def _build_status(self, config): self.status_raw_config.clear() for section in config.get_prefix_sections(''): @@ -298,9 +313,20 @@ class PrinterConfig: self.status_settings = {} for (section, option), value in config.access_tracking.items(): self.status_settings.setdefault(section, {})[option] = value + self.status_warnings = [] + for (section, option, value), msg in self.deprecated.items(): + if value is None: + res = {'type': 'deprecated_option'} + else: + res = {'type': 'deprecated_value', 'value': value} + res['message'] = msg + res['section'] = section + res['option'] = option + self.status_warnings.append(res) def get_status(self, eventtime): return {'config': self.status_raw_config, 'settings': self.status_settings, + 'warnings': self.status_warnings, 'save_config_pending': self.save_config_pending} # Autosave functions def set(self, section, option, value): |