diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-10-04 14:56:52 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-10-04 14:58:21 +0800 |
commit | 1e0d443c4c77a8a2cc0ae6e503e8811aca6b3e39 (patch) | |
tree | bdf3abce08cddcceff7bf9c8fec3dd9ace17d1cd /fg21sim/configs/manager.py | |
parent | 84edeab1f585aa07a36bc060f22ede812abf9669 (diff) | |
download | fg21sim-1e0d443c4c77a8a2cc0ae6e503e8811aca6b3e39.tar.bz2 |
Fix wrong config syntax and minor changes to ConfigManager
Diffstat (limited to 'fg21sim/configs/manager.py')
-rw-r--r-- | fg21sim/configs/manager.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py index 5987394..fe3c18f 100644 --- a/fg21sim/configs/manager.py +++ b/fg21sim/configs/manager.py @@ -128,13 +128,13 @@ class ConfigManager: """Get config value by key.""" return self._config.get(key, fallback) - def getn(self, keys, sep="/"): + def getn(self, key, sep="/"): """Get the config value from the nested dictionary configs using a list of keys or a "sep"-separated keys strings. Parameters ---------- - keys : str / list[str] + key : str / list[str] List of keys or a string separated by a specific character (e.g., "/") to specify the item in the `self._config`, which is a nested dictionary. @@ -148,21 +148,27 @@ class ConfigManager: - Stackoverflow: Checking a Dictionary using a dot notation string https://stackoverflow.com/q/12414821/4856091 """ - if isinstance(keys, str): - keys = keys.split(sep) - return reduce(dict.get, keys, self._config) + if isinstance(key, str): + key = key.split(sep) + return reduce(dict.get, key, self._config) - def get_path(self, keys): + def get_path(self, key): """Return the absolute path of the file/directory specified by the config keys. + Parameters + ---------- + key : str + "/"-separated string specifying the config name of the + file/directory + NOTE ---- - The "~" (tilde) inside path is expanded to the user home directory. - The relative path (with respect to the user configuration file) is converted to absolute path if `self.userconfig` presents. """ - path = os.path.expanduser(self.getn(keys)) + path = os.path.expanduser(self.getn(key)) if not os.path.isabs(path): # relative path if hasattr(self, "userconfig"): @@ -170,7 +176,7 @@ class ConfigManager: else: # cannot convert to the absolute path logger.warning("Cannot convert to absolute path: %s" % path) - return path + return os.path.normpath(path) @property def frequencies(self): |