From 1e0d443c4c77a8a2cc0ae6e503e8811aca6b3e39 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 4 Oct 2016 14:56:52 +0800 Subject: Fix wrong config syntax and minor changes to ConfigManager --- fg21sim/configs/manager.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'fg21sim/configs/manager.py') 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): -- cgit v1.2.2