From dee4165ac47a8184ea8ae0876bd45364ba40affa Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 4 Nov 2016 11:27:42 +0800 Subject: configs/manager.py: Add method "check_all()" using "check_configs()" --- fg21sim/configs/manager.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py index 5d7cf12..0809126 100644 --- a/fg21sim/configs/manager.py +++ b/fg21sim/configs/manager.py @@ -20,6 +20,7 @@ import pkg_resources from configobj import ConfigObj, ConfigObjError, flatten_errors from validate import Validator +from .checkers import check_configs from ..errors import ConfigError @@ -197,6 +198,36 @@ class ConfigManager: raise ConfigError(error_msg) return config + def check_all(self, raise_exception=True): + """Further check the whole configurations through a set of custom + checker functions, which may check one config option against its + context if necessary to determine whether it has a valid value. + + Parameters + ---------- + raise_exception : bool, optional + Whether raise a ``ConfigError`` exception if there is any invalid + config options? + + Returns + ------- + result : bool + ``True`` if the configurations pass all checker functions. + errors : dict + An dictionary containing the details about the invalid config + options, with the keys identifying the config options and values + indicating the error message. + If above ``result=True``, then this is an empty dictionary ``{}``. + + Raises + ------ + ConfigError + If any config option failed to pass any of the checkers, a + ``ConfigError`` with details is raised. + """ + result, errors = check_configs(self, raise_exception=raise_exception) + return (result, errors) + def get(self, key, fallback=None, from_default=False): """Get config value by key.""" if from_default: -- cgit v1.2.2