diff options
author | drebs <drebs@leap.se> | 2016-07-06 08:46:33 +0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2016-07-11 16:41:53 +0200 |
commit | 40e5d40c7c725709ac3fd770e6070fbe02e4b7e0 (patch) | |
tree | f8e1c22b4a7ebe12fd35a9fc44d7e65b4e2aa3fd /src/leap/common/config | |
parent | 7e90eed551bbe847201e5c62edcf0e6493ab2ec3 (diff) |
[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.
Diffstat (limited to 'src/leap/common/config')
-rw-r--r-- | src/leap/common/config/__init__.py | 22 |
1 files changed, 17 insertions, 5 deletions
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() |