summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-03-11 13:22:24 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-03-11 13:22:24 +0000
commitc01e925af1b9d960d77f9c053cc43d15da5e4d84 (patch)
tree637c0fcfa0013c63c4cf6e7f11d14050912605aa
parent9b8c0dd28b4bfa755ddf1470b698b863969edca8 (diff)
allow custom checks helper.read_config
this makes read_config accept a `checks` dict as parameter which it will add to the validator if validation is used. It allows us to define custom checks ~ value types in our spec
-rw-r--r--alot/helper.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 56250c71..7588e5aa 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -401,7 +401,7 @@ def humanize_size(size):
return format_string % (size / factor)
-def read_config(configpath=None, specpath=None):
+def read_config(configpath=None, specpath=None, checks={}):
"""
get a (validated) config object for given config file path.
@@ -409,6 +409,9 @@ def read_config(configpath=None, specpath=None):
:type configpath: str
:param specpath: path to spec-file
:type specpath: str
+ :param checks: custom checks to use for validator.
+ see `validate docs <http://www.voidspace.org.uk/python/validate.html>`_
+ :type checks: dict str->callable,
:rtype: `configobj.ConfigObj`
"""
try:
@@ -419,6 +422,7 @@ def read_config(configpath=None, specpath=None):
if specpath:
validator = Validator()
+ validator.functions.update(checks)
results = config.validate(validator)
if results != True: