diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-04 11:27:42 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-04 11:27:42 +0800 |
commit | dee4165ac47a8184ea8ae0876bd45364ba40affa (patch) | |
tree | 96bdac66ff7c0b9f775273a48a5c2f73bdfa35eb /fg21sim/configs/manager.py | |
parent | a0356d79e15e19b729e943fe22d2c484dbcb2b25 (diff) | |
download | fg21sim-dee4165ac47a8184ea8ae0876bd45364ba40affa.tar.bz2 |
configs/manager.py: Add method "check_all()" using "check_configs()"
Diffstat (limited to 'fg21sim/configs/manager.py')
-rw-r--r-- | fg21sim/configs/manager.py | 31 |
1 files changed, 31 insertions, 0 deletions
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: |