summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authordtk <dtk@gmx.de>2012-01-04 17:18:31 +0100
committerdtk <dtk@gmx.de>2012-01-04 18:11:04 +0100
commite702222b5e3d2b258230a35ee79c6e842a966d1a (patch)
treefff30a66261a9c18a2e79af43b743b52cbafd5f2 /alot
parent5d8481e733757a376231594c11e5f2f21ebcf086 (diff)
Adjust code to new FallbackConfigParser behaviour
Some of the methods in `AlotConfigParser` and code using the config parser used `get()` from the `FallbackConfigParser` to determine whether an option existed by inspecting the return value. This commit accommodates the fact that since 5d8481e733757a376231594c11e5f2f21ebcf086 the `FallbackConfigParser` doesn't return `None` on error but raises a `NoOptionError`. Cf https://github.com/pazz/alot/pull/226#commitcomment-836371 and https://github.com/pazz/alot/pull/226#issuecomment-3356448.
Diffstat (limited to 'alot')
-rw-r--r--alot/message.py4
-rw-r--r--alot/settings.py23
-rw-r--r--alot/widgets.py4
3 files changed, 18 insertions, 13 deletions
diff --git a/alot/message.py b/alot/message.py
index 1be06bcb..36f2a5ff 100644
--- a/alot/message.py
+++ b/alot/message.py
@@ -134,8 +134,8 @@ class Message(object):
"""
if self._datetime == None:
return None
- formatstring = config.get('general', 'timestamp_format')
- if formatstring:
+ if config.has_option('general', 'timestamp_format'):
+ formatstring = config.get('general', 'timestamp_format')
res = self._datetime.strftime(formatstring)
else:
res = helper.pretty_datetime(self._datetime)
diff --git a/alot/settings.py b/alot/settings.py
index eeb8dfd3..70ff0ef9 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -36,8 +36,11 @@ class FallbackConfigParser(SafeConfigParser):
def getstringlist(self, section, option, **kwargs):
"""directly parses a config value into a list of strings"""
- value = self.get(section, option, **kwargs)
- return [s.strip() for s in value.split(',') if s.strip()]
+ stringlist = list()
+ if self.has_option(section, option):
+ value = self.get(section, option, **kwargs)
+ stringlist = [s.strip() for s in value.split(',') if s.strip()]
+ return stringlist
class AlotConfigParser(FallbackConfigParser):
@@ -195,19 +198,19 @@ class AlotConfigParser(FallbackConfigParser):
mode = self.getint('general', 'colourmode')
base = 'tag_%s' % tag
if mode == 2:
- if self.get('1c-theme', base):
+ if self.has_option('1c-theme', base):
return base
elif mode == 16:
- has_fg = self.get('16c-theme', base + '_fg')
- has_bg = self.get('16c-theme', base + '_bg')
+ has_fg = self.has_option('16c-theme', base + '_fg')
+ has_bg = self.has_option('16c-theme', base + '_bg')
if has_fg or has_bg:
if focus:
return base + '_focus'
else:
return base
else: # highcolour
- has_fg = self.get('256c-theme', base + '_fg')
- has_bg = self.get('256c-theme', base + '_bg')
+ has_fg = self.has_option('256c-theme', base + '_fg')
+ has_bg = self.has_option('256c-theme', base + '_bg')
if has_fg or has_bg:
if focus:
return base + '_focus'
@@ -246,8 +249,10 @@ class AlotConfigParser(FallbackConfigParser):
:returns: a command line to be applied upon keypress
:rtype: str
"""
- cmdline = self.get(mode + '-maps', key)
- if not cmdline:
+ cmdline = None
+ if self.has_option(mode + '-maps', key):
+ cmdline = self.get(mode + '-maps', key)
+ elif self.has_option('global-maps', key):
cmdline = self.get('global-maps', key)
return cmdline
diff --git a/alot/widgets.py b/alot/widgets.py
index e56ceab1..17141917 100644
--- a/alot/widgets.py
+++ b/alot/widgets.py
@@ -93,8 +93,8 @@ class ThreadlineWidget(urwid.AttrMap):
if newest == None:
datestring = u' ' * 10
else:
- formatstring = config.get('general', 'timestamp_format')
- if formatstring:
+ if config.has_option('general', 'timestamp_format'):
+ formatstring = config.get('general', 'timestamp_format')
datestring = newest.strftime(formatstring)
else:
datestring = pretty_datetime(newest).rjust(10)