Skip to content

Commit

Permalink
add function in configfile to warn (#141)
Browse files Browse the repository at this point in the history
* add function in configfile to warn

* fix f string
  • Loading branch information
bwnance authored Feb 2, 2024
1 parent 6e741ee commit b76172c
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,19 @@ def log_config(self, config):
def deprecate(self, section, option, value=None, msg=None):
self.deprecated[(section, option, value)] = msg

def warn(self, type, msg, section=None, option=None, value=None):
res = {
"type": type,
"message": msg,
}
if section is not None:
res["section"] = section
if option is not None:
res["option"] = option
if value is not None:
res["value"] = value
self.status_warnings.append(res)

def _build_status(self, config):
self.status_raw_config.clear()
for section in config.get_prefix_sections(""):
Expand All @@ -485,30 +498,18 @@ def _build_status(self, config):
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)
_type = "deprecated_value"
self.warn(_type, msg, section, option, value)

for section, option in self.unused_options:
res = {"type": "unused_option"}
res["message"] = "Option '%s' in section '%s' is invalid" % (
option,
section,
)
res["section"] = section
res["option"] = option
self.status_warnings.append(res)
_type = "unused_option"
msg = f"Option '{option}' in section '{section}' is invalid"
self.warn(_type, msg, section, option)
for section in self.unused_sections:
res = {"type": "unused_section"}
res["message"] = "Section '%s' is invalid" % (section,)
res["section"] = section
self.status_warnings.append(res)
_type = "unused_section"
msg = f"Section '{section}' is invalid"
self.warn(_type, msg, section)

def get_status(self, eventtime):
return {
Expand Down

0 comments on commit b76172c

Please sign in to comment.