From 47384df0765d05c3a497d9be85751257d4d04266 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 30 Sep 2016 21:20:38 +0800 Subject: configs/manager.py: Update docstrings. The NumPy docstring style is used. --- fg21sim/configs/manager.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'fg21sim/configs') diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py index a889259..a24475b 100644 --- a/fg21sim/configs/manager.py +++ b/fg21sim/configs/manager.py @@ -29,8 +29,13 @@ CONFIGS_PATH = os.path.dirname(__file__) class ConfigManager: """Manager the configurations""" def __init__(self, configs=None): - """ - :param configs: (optional) list of user configs to load + """Initialize the ConfigManager object with default configurations. + If user configs are given, they are also validated and get merged. + + Parameters + ---------- + configs: list (of config files) + (optional) list of user config files to be merged """ configs_spec = sorted(glob(os.path.join(CONFIGS_PATH, "*.conf.spec"))) spec = "\n".join([open(f).read() for f in configs_spec]).split("\n") @@ -44,12 +49,25 @@ class ConfigManager: self.read_config(config) def read_config(self, config): + """Read, validate and merge the input config. + + Parameters + ---------- + config : str, list of str + Input config to be validated and merged. + This parameter can be the filename of the config file, or a list + contains the lines of the configs. + """ newconfig = ConfigObj(config, interpolation=False, configspec=self._configspec) newconfig = self.validate(newconfig) self._config.merge(newconfig) def validate(self, config): + """Validate the config against the specification using a default + validator. The validated config values are returned if success, + otherwise, the ``ConfigError`` raised with details. + """ validator = Validator() try: results = config.validate(validator, preserve_errors=True) @@ -72,6 +90,7 @@ class ConfigManager: return config def get(self, key, fallback=None): + """Get config value by key.""" if key in self._config: value = self._config[key] else: -- cgit v1.2.2