From 4b40133e2199e11ccd5dc48c2ad60ac06d056d0a Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Mon, 11 May 2015 16:24:28 -0400 Subject: Use appdirs for platform-independent locations Cache, data and config files live rooted in different places across different OS's. Use appdirs to find where. Depends-On: Ic939dea11b7476ec504d2bf65854a0781b1bfb39 Change-Id: I7338ae1d0442e0c5cc1ec4ae4d619fac319a4a28 --- README.rst | 22 ++++++++++++++++++++++ os_client_config/config.py | 29 +++++++++++++++++++---------- requirements.txt | 1 + 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 2c27153..4389b68 100644 --- a/README.rst +++ b/README.rst @@ -50,6 +50,28 @@ Service specific settings, like the nova service type, are set with the default service type as a prefix. For instance, to set a special service_type for trove (because you're using Rackspace) set: +Site Specific File Locations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In addition to `~/.config/openstack` and `/etc/openstack` - some platforms +have other locations they like to put things. `os-client-config` will also +look in an OS specific config dir + +* `USER_CONFIG_DIR` +* `SITE_CONFIG_DIR` + +`USER_CONFIG_DIR` is different on Linux, OSX and Windows. + +* Linux: `~/.config/openstack` +* OSX: `~/Library/Application Support/openstack` +* Windows: `C:\\Users\\USERNAME\\AppData\\Local\\OpenStack\\openstack` + +`SITE_CONFIG_DIR` is different on Linux, OSX and Windows. + +* Linux: `/etc/openstack` +* OSX: `/Library/Application Support/openstack` +* Windows: `C:\\ProgramData\\OpenStack\\openstack` + :: database_service_type: 'rax:database' diff --git a/os_client_config/config.py b/os_client_config/config.py index 64afdbd..dd4f37f 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -15,6 +15,7 @@ import os +import appdirs import yaml try: @@ -27,27 +28,35 @@ from os_client_config import defaults from os_client_config import exceptions from os_client_config import vendors -CONFIG_HOME = os.path.join(os.path.expanduser( - os.environ.get('XDG_CONFIG_HOME', os.path.join('~', '.config'))), - 'openstack') -CONFIG_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack'] +APPDIRS = appdirs.AppDirs('openstack', 'OpenStack', multipath='/etc') +CONFIG_HOME = APPDIRS.user_config_dir +CACHE_PATH = APPDIRS.user_cache_dir + +UNIX_CONFIG_HOME = os.path.join( + os.path.expanduser(os.path.join('~', '.config')), 'openstack') +UNIX_SITE_CONFIG_HOME = '/etc/openstack' + +SITE_CONFIG_HOME = APPDIRS.site_config_dir + +CONFIG_SEARCH_PATH = [ + os.getcwd(), + CONFIG_HOME, UNIX_CONFIG_HOME, + SITE_CONFIG_HOME, UNIX_SITE_CONFIG_HOME +] YAML_SUFFIXES = ('.yaml', '.yml') CONFIG_FILES = [ os.path.join(d, 'clouds' + s) for d in CONFIG_SEARCH_PATH for s in YAML_SUFFIXES ] -CACHE_PATH = os.path.join(os.path.expanduser( - os.environ.get('XDG_CACHE_PATH', os.path.join('~', '.cache'))), - 'openstack') -BOOL_KEYS = ('insecure', 'cache') -VENDOR_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack'] VENDOR_FILES = [ os.path.join(d, 'clouds-public' + s) - for d in VENDOR_SEARCH_PATH + for d in CONFIG_SEARCH_PATH for s in YAML_SUFFIXES ] +BOOL_KEYS = ('insecure', 'cache') + def set_default(key, value): defaults._defaults[key] = value diff --git a/requirements.txt b/requirements.txt index 498c5c3..894a70a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. PyYAML>=3.1.0 +appdirs>=1.3.0 -- cgit v1.2.1