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>
This commit is contained in:
Kevin O'Connor 2021-09-04 14:20:24 -04:00
parent c89db2480d
commit 46167cae67
7 changed files with 40 additions and 2 deletions

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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.

View File

@ -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)

View File

@ -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

View File

@ -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