summaryrefslogtreecommitdiff
path: root/alot/settings/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/settings/utils.py')
-rw-r--r--alot/settings/utils.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/alot/settings/utils.py b/alot/settings/utils.py
index 242fa63c..8d656b79 100644
--- a/alot/settings/utils.py
+++ b/alot/settings/utils.py
@@ -5,14 +5,16 @@ from __future__ import absolute_import
import logging
-from configobj import ConfigObj, ConfigObjError, flatten_errors
+from configobj import (ConfigObj, ConfigObjError, flatten_errors,
+ get_extra_values)
from validate import Validator
from urwid import AttrSpec
from .errors import ConfigError
-def read_config(configpath=None, specpath=None, checks=None):
+def read_config(configpath=None, specpath=None, checks=None,
+ report_extra=False):
"""
get a (validated) config object for given config file path.
@@ -23,6 +25,8 @@ def read_config(configpath=None, specpath=None, checks=None):
:param checks: custom checks to use for validator.
see `validate docs <http://www.voidspace.org.uk/python/validate.html>`_
:type checks: dict str->callable,
+ :param report_extra: log if a setting is not present in the spec file
+ :type report_extra: boolean
:raises: :class:`~alot.settings.errors.ConfigError`
:rtype: `configobj.ConfigObj`
"""
@@ -65,6 +69,18 @@ def read_config(configpath=None, specpath=None, checks=None):
msg = 'section "%s" is missing' % '.'.join(section_list)
error_msg += msg + '\n'
raise ConfigError(error_msg)
+
+ extra_values = get_extra_values(config) if report_extra else None
+ if extra_values:
+ msg = ['Unknown values were found in `%s`. Please check for '
+ 'typos if a specified setting does not seem to work:'
+ % configpath]
+ for sections, val in extra_values:
+ if sections:
+ msg.append('%s: %s' % ('->'.join(sections), val))
+ else:
+ msg.append(str(val))
+ logging.info('\n'.join(msg))
return config