mirror of https://github.com/Desuuuu/klipper.git
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:
parent
c89db2480d
commit
46167cae67
|
@ -28,6 +28,12 @@ The following information is available in the `configfile` object
|
||||||
setting as read by Klipper during the last software start or
|
setting as read by Klipper during the last software start or
|
||||||
restart. (Any settings changed at run-time will not be reflected
|
restart. (Any settings changed at run-time will not be reflected
|
||||||
here.) All values are returned as strings.
|
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
|
## display_status
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,17 @@ class ConfigWrapper:
|
||||||
def get_prefix_options(self, prefix):
|
def get_prefix_options(self, prefix):
|
||||||
return [o for o in self.fileconfig.options(self.section)
|
return [o for o in self.fileconfig.options(self.section)
|
||||||
if o.startswith(prefix)]
|
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 = """
|
AUTOSAVE_HEADER = """
|
||||||
#*# <---------------------- SAVE_CONFIG ---------------------->
|
#*# <---------------------- SAVE_CONFIG ---------------------->
|
||||||
|
@ -127,8 +138,10 @@ class PrinterConfig:
|
||||||
def __init__(self, printer):
|
def __init__(self, printer):
|
||||||
self.printer = printer
|
self.printer = printer
|
||||||
self.autosave = None
|
self.autosave = None
|
||||||
|
self.deprecated = {}
|
||||||
self.status_raw_config = {}
|
self.status_raw_config = {}
|
||||||
self.status_settings = {}
|
self.status_settings = {}
|
||||||
|
self.status_warnings = []
|
||||||
self.save_config_pending = False
|
self.save_config_pending = False
|
||||||
gcode = self.printer.lookup_object('gcode')
|
gcode = self.printer.lookup_object('gcode')
|
||||||
gcode.register_command("SAVE_CONFIG", self.cmd_SAVE_CONFIG,
|
gcode.register_command("SAVE_CONFIG", self.cmd_SAVE_CONFIG,
|
||||||
|
@ -289,6 +302,8 @@ class PrinterConfig:
|
||||||
"======================="]
|
"======================="]
|
||||||
self.printer.set_rollover_info("config", "\n".join(lines))
|
self.printer.set_rollover_info("config", "\n".join(lines))
|
||||||
# Status reporting
|
# Status reporting
|
||||||
|
def deprecate(self, section, option, value=None, msg=None):
|
||||||
|
self.deprecated[(section, option, value)] = msg
|
||||||
def _build_status(self, config):
|
def _build_status(self, config):
|
||||||
self.status_raw_config.clear()
|
self.status_raw_config.clear()
|
||||||
for section in config.get_prefix_sections(''):
|
for section in config.get_prefix_sections(''):
|
||||||
|
@ -298,9 +313,20 @@ class PrinterConfig:
|
||||||
self.status_settings = {}
|
self.status_settings = {}
|
||||||
for (section, option), value in config.access_tracking.items():
|
for (section, option), value in config.access_tracking.items():
|
||||||
self.status_settings.setdefault(section, {})[option] = value
|
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):
|
def get_status(self, eventtime):
|
||||||
return {'config': self.status_raw_config,
|
return {'config': self.status_raw_config,
|
||||||
'settings': self.status_settings,
|
'settings': self.status_settings,
|
||||||
|
'warnings': self.status_warnings,
|
||||||
'save_config_pending': self.save_config_pending}
|
'save_config_pending': self.save_config_pending}
|
||||||
# Autosave functions
|
# Autosave functions
|
||||||
def set(self, section, option, value):
|
def set(self, section, option, value):
|
||||||
|
|
|
@ -141,8 +141,10 @@ class GCodeMacro:
|
||||||
desc=self.cmd_SET_GCODE_VARIABLE_help)
|
desc=self.cmd_SET_GCODE_VARIABLE_help)
|
||||||
self.in_script = False
|
self.in_script = False
|
||||||
prefix = 'default_parameter_'
|
prefix = 'default_parameter_'
|
||||||
self.kwparams = { o[len(prefix):].upper(): config.get(o)
|
self.kwparams = {}
|
||||||
for o in config.get_prefix_options(prefix) }
|
for option in config.get_prefix_options(prefix):
|
||||||
|
config.deprecate(option)
|
||||||
|
self.kwparams[option[len(prefix):].upper()] = config.get(option)
|
||||||
self.variables = {}
|
self.variables = {}
|
||||||
prefix = 'variable_'
|
prefix = 'variable_'
|
||||||
for option in config.get_prefix_options(prefix):
|
for option in config.get_prefix_options(prefix):
|
||||||
|
|
|
@ -180,6 +180,7 @@ class ControlPID:
|
||||||
self.Ki = config.getfloat('pid_Ki') / PID_PARAM_BASE
|
self.Ki = config.getfloat('pid_Ki') / PID_PARAM_BASE
|
||||||
self.Kd = config.getfloat('pid_Kd') / PID_PARAM_BASE
|
self.Kd = config.getfloat('pid_Kd') / PID_PARAM_BASE
|
||||||
self.min_deriv_time = heater.get_smooth_time()
|
self.min_deriv_time = heater.get_smooth_time()
|
||||||
|
config.deprecate('pid_integral_max')
|
||||||
imax = config.getfloat('pid_integral_max', self.heater_max_power,
|
imax = config.getfloat('pid_integral_max', self.heater_max_power,
|
||||||
minval=0.)
|
minval=0.)
|
||||||
self.temp_integ_max = 0.
|
self.temp_integ_max = 0.
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Temperature_HOST:
|
||||||
|
|
||||||
if config.get("sensor_type", "", note_valid=False).startswith('rpi'):
|
if config.get("sensor_type", "", note_valid=False).startswith('rpi'):
|
||||||
# Temporary backwards compatibility
|
# Temporary backwards compatibility
|
||||||
|
config.deprecate("sensor_type", "rpi_temperature")
|
||||||
self.printer.add_object("rpi_temperature " + self.name, self)
|
self.printer.add_object("rpi_temperature " + self.name, self)
|
||||||
else:
|
else:
|
||||||
self.printer.add_object("temperature_host " + self.name, self)
|
self.printer.add_object("temperature_host " + self.name, self)
|
||||||
|
|
|
@ -560,6 +560,7 @@ class MCU:
|
||||||
self._config_cmds = []
|
self._config_cmds = []
|
||||||
self._restart_cmds = []
|
self._restart_cmds = []
|
||||||
self._init_cmds = []
|
self._init_cmds = []
|
||||||
|
config.deprecate('pin_map')
|
||||||
self._pin_map = config.get('pin_map', None)
|
self._pin_map = config.get('pin_map', None)
|
||||||
self._mcu_freq = 0.
|
self._mcu_freq = 0.
|
||||||
# Move command queuing
|
# Move command queuing
|
||||||
|
|
|
@ -233,6 +233,7 @@ def parse_step_distance(config, units_in_radians=None, note_valid=False):
|
||||||
config.get('gear_ratio', note_valid=note_valid)
|
config.get('gear_ratio', note_valid=note_valid)
|
||||||
else:
|
else:
|
||||||
rd = config.get('rotation_distance', None, note_valid=False)
|
rd = config.get('rotation_distance', None, note_valid=False)
|
||||||
|
config.deprecate('step_distance')
|
||||||
sd = config.get('step_distance', None, note_valid=False)
|
sd = config.get('step_distance', None, note_valid=False)
|
||||||
if rd is None and sd is not None:
|
if rd is None and sd is not None:
|
||||||
# Older config format with step_distance
|
# Older config format with step_distance
|
||||||
|
|
Loading…
Reference in New Issue