diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-11-30 15:50:28 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-11-30 21:19:44 -0500 |
commit | 2f97b2d7c250d4612654824633122b63d917a937 (patch) | |
tree | c43f5cb774c3c0e27349161826b8da8ff08857e7 /klippy/klippy.py | |
parent | 57244de37d6b4e2247c09803d06728daacfdaa48 (diff) | |
download | kutter-2f97b2d7c250d4612654824633122b63d917a937.tar.gz kutter-2f97b2d7c250d4612654824633122b63d917a937.tar.xz kutter-2f97b2d7c250d4612654824633122b63d917a937.zip |
klippy: Add ConfigWrapper.getchoice method
Add helper function that ensures a config option is one of several
choices. This helps ensure that a proper error is raised if an
invalid choice is made.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r-- | klippy/klippy.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py index bf63d01d..f4cdbb41 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -61,6 +61,13 @@ class ConfigWrapper: def getboolean(self, option, default=sentinel): return self.get_wrapper( self.printer.fileconfig.getboolean, option, default) + def getchoice(self, option, choices, default=sentinel): + c = self.get(option, default) + if c not in choices: + raise self.error( + "Option '%s' in section '%s' is not a valid choice" % ( + option, self.section)) + return choices[c] def getsection(self, section): return ConfigWrapper(self.printer, section) |