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.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/alot/settings/utils.py b/alot/settings/utils.py
index 316083aa..c7c5bffa 100644
--- a/alot/settings/utils.py
+++ b/alot/settings/utils.py
@@ -11,13 +11,14 @@ from validate import Validator
from .errors import ConfigError
-def read_config(configpath=None, specpath=None, checks=None,
+def read_config(configs = None, specpath=None, checks=None,
report_extra=False):
"""
get a (validated) config object for given config file path.
- :param configpath: path to config-file or a list of lines as its content
- :type configpath: str or list(str)
+ :param configs: list of configurations; each configuration is either a path
+ to a config file or a list of lines to parse as configuration
+ :type configs: list
:param specpath: path to spec-file
:type specpath: str
:param checks: custom checks to use for validator.
@@ -30,20 +31,23 @@ def read_config(configpath=None, specpath=None, checks=None,
"""
checks = checks or {}
- try:
- config = ConfigObj(infile=configpath, configspec=specpath,
- file_error=True, encoding='UTF8')
- except ConfigObjError as e:
- msg = 'Error when parsing `%s`:\n%s' % (configpath, e)
- logging.error(msg)
- raise ConfigError(msg)
- except IOError:
- raise ConfigError('Could not read %s and/or %s'
- % (configpath, specpath))
- except UnboundLocalError:
- # this works around a bug in configobj
- msg = '%s is malformed. Check for sections without parents..'
- raise ConfigError(msg % configpath)
+ config = ConfigObj(configspec = specpath)
+
+ for cf in configs:
+ try:
+ c = ConfigObj(infile = cf, configspec = specpath,
+ file_error = True, encoding = 'UTF8')
+ except ConfigObjError as e:
+ msg = 'Error when parsing `%s`:\n%s' % (cf, e)
+ logging.error(msg)
+ raise ConfigError(msg)
+ except IOError:
+ raise ConfigError('Could not read %s and/or %s' % (cf, specpath))
+ except UnboundLocalError:
+ # this works around a bug in configobj
+ msg = '%s is malformed. Check for sections without parents..' % cf
+ raise ConfigError(msg)
+ config.merge(c)
if specpath:
validator = Validator()
@@ -70,9 +74,8 @@ def read_config(configpath=None, specpath=None, checks=None,
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]
+ msg = ['Unknown values were found in the config. Please check for '
+ 'typos if a specified setting does not seem to work:']
for sections, val in extra_values:
if sections:
msg.append('%s: %s' % ('->'.join(sections), val))