diff options
author | Julian Mehne <julian.mehne@posteo.de> | 2018-01-07 22:28:30 +0100 |
---|---|---|
committer | Julian Mehne <julian.mehne@posteo.de> | 2018-01-08 17:51:07 +0100 |
commit | edd6c76123c033b9ddc53d674ae396f5ac9fe305 (patch) | |
tree | fdd9e62ddf90c21a83b4392ad27038605c1183ab /alot/settings | |
parent | 29ca68415ba51fbaa979865ce83cae709585a4dc (diff) |
Log unknown settings in configuration and theme files.
Diffstat (limited to 'alot/settings')
-rw-r--r-- | alot/settings/manager.py | 2 | ||||
-rw-r--r-- | alot/settings/theme.py | 2 | ||||
-rw-r--r-- | alot/settings/utils.py | 20 |
3 files changed, 20 insertions, 4 deletions
diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 10a441ed..dffe1b32 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -79,7 +79,7 @@ class SettingsManager(object): """parse alot's config file from path""" spec = os.path.join(DEFAULTSPATH, 'alot.rc.spec') newconfig = read_config( - self.alot_rc_path, spec, checks={ + self.alot_rc_path, spec, report_extra=True, checks={ 'mail_container': checks.mail_container, 'force_list': checks.force_list, 'align': checks.align_mode, diff --git a/alot/settings/theme.py b/alot/settings/theme.py index f2a59763..d74cb0e7 100644 --- a/alot/settings/theme.py +++ b/alot/settings/theme.py @@ -22,7 +22,7 @@ class Theme(object): :raises: :class:`~alot.settings.errors.ConfigError` """ self._spec = os.path.join(DEFAULTSPATH, 'theme.spec') - self._config = read_config(path, self._spec, + self._config = read_config(path, self._spec, report_extra=True, checks={'align': checks.align_mode, 'widthtuple': checks.width_tuple, 'force_list': checks.force_list, 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 |