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>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user