aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-10-04 13:26:55 +0800
committerAaron LI <aaronly.me@outlook.com>2016-10-04 13:26:55 +0800
commit0f4b966c3e111b65422ce29a24b64bdb8ba75405 (patch)
treebcdbaf1fb37b061d22376469f3a8adf944b97397 /fg21sim
parent9d63da1b5947965d38a860b6cb5bcfc3deb982a5 (diff)
downloadfg21sim-0f4b966c3e111b65422ce29a24b64bdb8ba75405.tar.bz2
configs/manager.py: Add method "get_path()"
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/configs/manager.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py
index caf0bc4..6e8545b 100644
--- a/fg21sim/configs/manager.py
+++ b/fg21sim/configs/manager.py
@@ -147,6 +147,27 @@ class ConfigManager:
keys = keys.split(sep)
return reduce(dict.get, keys, self._config)
+ def get_path(self, keys):
+ """Return the absolute path of the file/directory specified by the
+ config keys.
+
+ 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))
+ if not os.path.isabs(path):
+ # relative path
+ if hasattr(self, "userconfig"):
+ path = os.path.join(os.path.dirname(self.userconfig), path)
+ else:
+ # cannot convert to the absolute path
+ print("WARNING: cannot convert to the absolute path!",
+ file=sys.stderr)
+ return path
+
@property
def frequencies(self):
"""Get (calculate if necessary) )the frequencies at which to