diff options
Diffstat (limited to 'src/config.py')
-rw-r--r-- | src/config.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/config.py b/src/config.py index 8bc0d863..af9c9fbe 100644 --- a/src/config.py +++ b/src/config.py @@ -46,10 +46,26 @@ class Config(RawConfigParser): res = self.getboolean(option, section) else: res = self.getstr(option, section) - except( NoOptionError, NoSectionError): + except (NoOptionError, NoSectionError): return default return res + def get_by_tabname(self, option, default, tabname, fallback=True): + """ + Try to get the value for the option. First we look in + a section named `tabname`, if the option is not present + in the section, we search for the global option if fallback is + True. And we return `default` as a fallback as a last resort. + """ + if tabname in self.sections(): + if option in self.options(tabname): + # We go the tab-specific option + return self.get(option, default, tabname) + if fallback: + # We fallback to the global option + return self.get(option, default) + return default + def __get(self, option, section=DEFSECTION): """ facility for RawConfigParser.get |