From 7783767c35c5924819ef0dc06e5e62a8d5c85698 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 3 Aug 2018 18:54:23 -0400 Subject: [PATCH] klippy: Move tracking of accessed config items into _read_config() method Signed-off-by: Kevin O'Connor --- klippy/klippy.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/klippy/klippy.py b/klippy/klippy.py index ba6b4579..2b98fda6 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -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))