klippy: Move tracking of accessed config items into _read_config() method

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-08-03 18:54:23 -04:00
parent cd24d61515
commit 7783767c35
1 changed files with 9 additions and 8 deletions

View File

@ -50,9 +50,10 @@ class ConfigWrapper:
error = ConfigParser.Error
class sentinel:
pass
def __init__(self, printer, fileconfig, section):
def __init__(self, printer, fileconfig, access_tracking, section):
self.printer = printer
self.fileconfig = fileconfig
self.access_tracking = access_tracking
self.section = section
def get_printer(self):
return self.printer
@ -63,8 +64,7 @@ class ConfigWrapper:
if (default is not self.sentinel
and not self.fileconfig.has_option(self.section, option)):
return default
self.printer.all_config_options[
(self.section.lower(), option.lower())] = 1
self.access_tracking[(self.section.lower(), option.lower())] = 1
try:
v = parser(self.section, option)
except self.error as e:
@ -108,7 +108,8 @@ class ConfigWrapper:
" is not a valid choice" % (c, option, self.section))
return choices[c]
def getsection(self, section):
return ConfigWrapper(self.printer, self.fileconfig, section)
return ConfigWrapper(self.printer, self.fileconfig,
self.access_tracking, section)
def has_section(self, section):
return self.fileconfig.has_section(section)
def get_prefix_sections(self, prefix):
@ -137,7 +138,6 @@ class Printer:
self.stats_timer = self.reactor.register_timer(self._stats)
self.connect_timer = self.reactor.register_timer(
self._connect, self.reactor.NOW)
self.all_config_options = {}
self.state_message = message_startup
self.is_shutdown = False
self.async_shutdown_msg = ""
@ -211,7 +211,8 @@ class Printer:
if self.bglogger is not None:
ConfigLogger(fileconfig, self.bglogger)
# Create printer components
config = ConfigWrapper(self, fileconfig, 'printer')
access_tracking = {}
config = ConfigWrapper(self, fileconfig, access_tracking, 'printer')
for m in [pins, heater, mcu]:
m.add_printer_objects(config)
for section in fileconfig.sections():
@ -219,7 +220,7 @@ class Printer:
for m in [toolhead]:
m.add_printer_objects(config)
# Validate that there are no undefined parameters in the config file
valid_sections = { s: 1 for s, o in self.all_config_options }
valid_sections = { s: 1 for s, o in access_tracking }
for section_name in fileconfig.sections():
section = section_name.lower()
if section not in valid_sections and section not in self.objects:
@ -227,7 +228,7 @@ class Printer:
"Section '%s' is not a valid config section" % (section,))
for option in fileconfig.options(section_name):
option = option.lower()
if (section, option) not in self.all_config_options:
if (section, option) not in access_tracking:
raise self.config_error(
"Option '%s' is not valid in section '%s'" % (
option, section))