aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/klippy.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-30 16:07:17 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-30 21:20:09 -0500
commit17dcb4275246a3826766d2b102b26ad6b3e931a6 (patch)
tree73e1e029f6216ff0e9a958574d288d7e5d7dd709 /klippy/klippy.py
parent2f97b2d7c250d4612654824633122b63d917a937 (diff)
downloadkutter-17dcb4275246a3826766d2b102b26ad6b3e931a6.tar.gz
kutter-17dcb4275246a3826766d2b102b26ad6b3e931a6.tar.xz
kutter-17dcb4275246a3826766d2b102b26ad6b3e931a6.zip
klippy: Validate that options in the config file exist
Check that all options specified in the config file are valid. This catches possible typos and spelling errors in variable names that have a default. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r--klippy/klippy.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py
index f4cdbb41..9b7a68ab 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -44,6 +44,8 @@ class ConfigWrapper:
if (default is not self.sentinel
and not self.printer.fileconfig.has_option(self.section, option)):
return default
+ self.printer.all_config_options[
+ (self.section.lower(), option.lower())] = 1
try:
return parser(self.section, option)
except self.error, e:
@@ -79,6 +81,7 @@ 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.debugoutput = self.dictionary = None
self.fileconfig = None
@@ -118,6 +121,19 @@ class Printer:
self.objects[oname].build_config()
self.gcode.build_config()
self.mcu.build_config()
+ def validate_config(self):
+ valid_sections = dict([(s, 1) for s, o in self.all_config_options])
+ for section in self.fileconfig.sections():
+ section = section.lower()
+ if section not in valid_sections:
+ raise ConfigParser.Error("Unknown config file section '%s'" % (
+ section,))
+ for option in self.fileconfig.options(section):
+ option = option.lower()
+ if (section, option) not in self.all_config_options:
+ raise ConfigParser.Error(
+ "Unknown option '%s' in section '%s'" % (
+ option, section))
def connect(self, eventtime):
try:
self.load_config()
@@ -127,6 +143,7 @@ class Printer:
self.mcu.connect_file(self.debugoutput, self.dictionary)
self.mcu.connect()
self.build_config()
+ self.validate_config()
self.gcode.set_printer_ready(True)
self.state_message = "Running"
except ConfigParser.Error, e: