configfile: Support config.getchoice() with integer keys

If the choice mapping uses integer keys then lookup the config option
using self.getint().  This simplifies the callers and improves the
encoding of the printer.configfile.settings export.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2021-08-25 10:36:45 -04:00
parent 75183bfb86
commit 84ac5b0146
5 changed files with 24 additions and 24 deletions

View File

@@ -69,7 +69,10 @@ class ConfigWrapper:
return self._get_wrapper(self.fileconfig.getboolean, option, default,
note_valid=note_valid)
def getchoice(self, option, choices, default=sentinel, note_valid=True):
c = self.get(option, default, note_valid=note_valid)
if choices and type(list(choices.keys())[0]) == int:
c = self.getint(option, default, note_valid=note_valid)
else:
c = self.get(option, default, note_valid=note_valid)
if c not in choices:
raise error("Choice '%s' for option '%s' in section '%s'"
" is not a valid choice" % (c, option, self.section))