From 40e5d40c7c725709ac3fd770e6070fbe02e4b7e0 Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 6 Jul 2016 08:46:33 +0200 Subject: [pkg] remove dependency on dirspec This commit removes the dep introduced in 5e12233 by just importing some tiny bit of dirspec code. The previous change was introduced because: * pyxdg did not account for Mac OS specifics, i.e. using ~/Library/ directory structure instead of .config (see: https://leap.se/code/issues/3574). * dirspec does the correct thing for xdg on Mac OS. * u1db depends on dirspec anyway. The problem is that dirspec is not maintained and published on pypi, what forces us to download it from an URL and add exceptions to be able to pip install it. As we are removing dependence on u1db on other modules, we can also remove it here. To workaround the Mac OS problem, we just add some code from dirspec to ensure we get the correct directory on Mac OS. --- src/leap/common/config/__init__.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/leap/common/config/__init__.py b/src/leap/common/config/__init__.py index 68d92dc..15c6fea 100644 --- a/src/leap/common/config/__init__.py +++ b/src/leap/common/config/__init__.py @@ -18,8 +18,22 @@ Common configs """ import os +import sys -from dirspec.basedir import get_xdg_config_home + +def _get_xdg_config_home(): + if sys.platform == 'win32': + from win32com.shell import shell, shellcon + get_path = lambda name: shell.SHGetFolderPath( + 0, getattr(shellcon, name), None, 0).encode('utf8') + path = get_path('CSIDL_LOCAL_APPDATA') + elif sys.platform == 'darwin': + user_home = os.path.expanduser('~') + path = os.path.join(user_home, 'Library', 'Preferences') + else: + user_home = os.path.expanduser('~') + path = os.path.join(user_home, '.config') + return path def get_path_prefix(standalone=False): @@ -32,8 +46,6 @@ def get_path_prefix(standalone=False): configuration storage. :type standalone: bool """ - config_home = get_xdg_config_home() if standalone: - config_home = os.path.join(os.getcwd(), "config") - - return config_home + return os.path.join(os.getcwd(), "config") + return _get_xdg_config_home() -- cgit v1.2.3