summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-08-11 12:21:51 +0100
committerMark McLoughlin <markmc@redhat.com>2012-08-11 12:24:03 +0100
commit0a36c92e84be0f432b8ce792834dc297196e09af (patch)
treef683810c4694ac483f473a367f3ed09163a05111 /openstack/common
parent887e9e169cd81dec7d7c01ce508e15d4e4fdd99e (diff)
downloadoslo-0a36c92e84be0f432b8ce792834dc297196e09af.tar.gz
oslo-0a36c92e84be0f432b8ce792834dc297196e09af.tar.xz
oslo-0a36c92e84be0f432b8ce792834dc297196e09af.zip
Tilde expansion for --config-file and --config-dir
Fixes bug #1012671 Allow a filename starting with ~ or ~user to be passed for --config-file or --config-dir. Change-Id: I67705401ed1c35c0cc2161095e36616552740aba
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/cfg.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py
index b42c30e..09f3b88 100644
--- a/openstack/common/cfg.py
+++ b/openstack/common/cfg.py
@@ -367,6 +367,11 @@ class ConfigFileValueError(Error):
pass
+def _fixpath(p):
+ """Apply tilde expansion and absolutization to a path."""
+ return os.path.abspath(os.path.expanduser(p))
+
+
def _get_config_dirs(project=None):
"""Return a list of directors where config files may be located.
@@ -384,11 +389,9 @@ def _get_config_dirs(project=None):
~/
/etc/
"""
- fix_path = lambda p: os.path.abspath(os.path.expanduser(p))
-
cfg_dirs = [
- fix_path(os.path.join('~', '.' + project)) if project else None,
- fix_path('~'),
+ _fixpath(os.path.join('~', '.' + project)) if project else None,
+ _fixpath('~'),
os.path.join('/etc', project) if project else None,
'/etc'
]
@@ -1268,10 +1271,10 @@ class ConfigOpts(collections.Mapping):
"""
dirs = []
if self.config_dir:
- dirs.append(self.config_dir)
+ dirs.append(_fixpath(self.config_dir))
for cf in reversed(self.config_file):
- dirs.append(os.path.dirname(cf))
+ dirs.append(os.path.dirname(_fixpath(cf)))
dirs.extend(_get_config_dirs(self.project))
@@ -1452,6 +1455,8 @@ class ConfigOpts(collections.Mapping):
config_dir_glob = os.path.join(self.config_dir, '*.conf')
config_files += sorted(glob.glob(config_dir_glob))
+ config_files = [_fixpath(p) for p in config_files]
+
self._cparser = MultiConfigParser()
try: