mirror of
https://github.com/Klipper3d/klipper.git
synced 2026-03-05 09:34:41 -07:00
configfile: Only warn once for each message sent to runtime_warning()
Also simplify the maintenance of warnings. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
8a210d23fe
commit
1473b79ac0
1 changed files with 25 additions and 27 deletions
|
|
@ -130,14 +130,8 @@ class ConfigWrapper:
|
|||
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)
|
||||
pconfig.deprecate(self.section, option, value)
|
||||
|
||||
|
||||
######################################################################
|
||||
|
|
@ -468,8 +462,6 @@ class PrinterConfig:
|
|||
self.autosave = ConfigAutoSave(printer)
|
||||
self.validate = ConfigValidate(printer)
|
||||
self.deprecated = {}
|
||||
self.runtime_warnings = []
|
||||
self.deprecate_warnings = []
|
||||
self.status_raw_config = {}
|
||||
self.status_warnings = []
|
||||
def get_printer(self):
|
||||
|
|
@ -496,27 +488,33 @@ class PrinterConfig:
|
|||
def check_unused_options(self, config):
|
||||
self.validate.check_unused(config.fileconfig)
|
||||
# Deprecation warnings
|
||||
def _add_deprecated(self, data):
|
||||
key = tuple(list(data.items()))
|
||||
if key in self.deprecated:
|
||||
return False
|
||||
self.deprecated[key] = True
|
||||
self.status_warnings = self.status_warnings + [data]
|
||||
return True
|
||||
def runtime_warning(self, msg):
|
||||
logging.warning(msg)
|
||||
res = {'type': 'runtime_warning', 'message': msg}
|
||||
self.runtime_warnings.append(res)
|
||||
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
|
||||
did_add = self._add_deprecated(res)
|
||||
if did_add:
|
||||
logging.warning(msg)
|
||||
def deprecate(self, section, option, value=None, msg=None):
|
||||
key = (section, option, value)
|
||||
if key in self.deprecated and self.deprecated[key] == msg:
|
||||
return
|
||||
self.deprecated[key] = msg
|
||||
self.deprecate_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.deprecate_warnings.append(res)
|
||||
self.status_warnings = self.runtime_warnings + self.deprecate_warnings
|
||||
if value is None:
|
||||
res = {'type': 'deprecated_option'}
|
||||
defmsg = ("Option '%s' in section '%s' is deprecated."
|
||||
% (option, self.section))
|
||||
else:
|
||||
res = {'type': 'deprecated_value', 'value': value}
|
||||
defmsg = ("Value '%s' in option '%s' in section '%s' is deprecated."
|
||||
% (value, option, self.section))
|
||||
if msg is None:
|
||||
msg = defmsg
|
||||
res['message'] = msg
|
||||
res['section'] = section
|
||||
res['option'] = option
|
||||
self._add_deprecated(res)
|
||||
# Status reporting
|
||||
def _build_status_config(self, config):
|
||||
self.status_raw_config = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue