aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-09-04 14:20:24 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-09-16 13:44:54 -0400
commit46167cae672073b1ce0aeb4966b30c28bc47957e (patch)
tree52ea9318147b065b6848970e6821f7260e1f4190
parentc89db2480df57204d805f52c9c488e251bafe631 (diff)
downloadkutter-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>
-rw-r--r--docs/Status_Reference.md6
-rw-r--r--klippy/configfile.py26
-rw-r--r--klippy/extras/gcode_macro.py6
-rw-r--r--klippy/extras/heaters.py1
-rw-r--r--klippy/extras/temperature_host.py1
-rw-r--r--klippy/mcu.py1
-rw-r--r--klippy/stepper.py1
7 files changed, 40 insertions, 2 deletions
diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md
index 68abf2f6..049ddf1a 100644
--- a/docs/Status_Reference.md
+++ b/docs/Status_Reference.md
@@ -28,6 +28,12 @@ The following information is available in the `configfile` object
setting as read by Klipper during the last software start or
restart. (Any settings changed at run-time will not be reflected
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.
+- `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
+ on the type of warning.
## display_status
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):
diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py
index 444614e6..fffeed06 100644
--- a/klippy/extras/gcode_macro.py
+++ b/klippy/extras/gcode_macro.py
@@ -141,8 +141,10 @@ class GCodeMacro:
desc=self.cmd_SET_GCODE_VARIABLE_help)
self.in_script = False
prefix = 'default_parameter_'
- self.kwparams = { o[len(prefix):].upper(): config.get(o)
- for o in config.get_prefix_options(prefix) }
+ self.kwparams = {}
+ for option in config.get_prefix_options(prefix):
+ config.deprecate(option)
+ self.kwparams[option[len(prefix):].upper()] = config.get(option)
self.variables = {}
prefix = 'variable_'
for option in config.get_prefix_options(prefix):
diff --git a/klippy/extras/heaters.py b/klippy/extras/heaters.py
index b9f60e63..048f293e 100644
--- a/klippy/extras/heaters.py
+++ b/klippy/extras/heaters.py
@@ -180,6 +180,7 @@ class ControlPID:
self.Ki = config.getfloat('pid_Ki') / PID_PARAM_BASE
self.Kd = config.getfloat('pid_Kd') / PID_PARAM_BASE
self.min_deriv_time = heater.get_smooth_time()
+ config.deprecate('pid_integral_max')
imax = config.getfloat('pid_integral_max', self.heater_max_power,
minval=0.)
self.temp_integ_max = 0.
diff --git a/klippy/extras/temperature_host.py b/klippy/extras/temperature_host.py
index 3950106c..6097dbe2 100644
--- a/klippy/extras/temperature_host.py
+++ b/klippy/extras/temperature_host.py
@@ -20,6 +20,7 @@ class Temperature_HOST:
if config.get("sensor_type", "", note_valid=False).startswith('rpi'):
# Temporary backwards compatibility
+ config.deprecate("sensor_type", "rpi_temperature")
self.printer.add_object("rpi_temperature " + self.name, self)
else:
self.printer.add_object("temperature_host " + self.name, self)
diff --git a/klippy/mcu.py b/klippy/mcu.py
index d568d194..f4d8d5a5 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -560,6 +560,7 @@ class MCU:
self._config_cmds = []
self._restart_cmds = []
self._init_cmds = []
+ config.deprecate('pin_map')
self._pin_map = config.get('pin_map', None)
self._mcu_freq = 0.
# Move command queuing
diff --git a/klippy/stepper.py b/klippy/stepper.py
index b71eda94..8fbd86cd 100644
--- a/klippy/stepper.py
+++ b/klippy/stepper.py
@@ -233,6 +233,7 @@ def parse_step_distance(config, units_in_radians=None, note_valid=False):
config.get('gear_ratio', note_valid=note_valid)
else:
rd = config.get('rotation_distance', None, note_valid=False)
+ config.deprecate('step_distance')
sd = config.get('step_distance', None, note_valid=False)
if rd is None and sd is not None:
# Older config format with step_distance