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