From 6a4ad31125981efec78189d0f11f6c6bf89b7114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Thu, 18 Apr 2019 21:19:03 -0300 Subject: [PATCH] Add support for the XDG Base Directory Specification. --- grip/app.py | 9 +++++++-- grip/settings.py | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/grip/app.py b/grip/app.py index 137ac4d..e065f69 100644 --- a/grip/app.py +++ b/grip/app.py @@ -63,7 +63,10 @@ def __init__(self, source=None, auth=None, renderer=None, if instance_path is None: instance_path = os.environ.get('GRIPHOME') if instance_path is None: - instance_path = DEFAULT_GRIPHOME + instance_path = os.path.expanduser(DEFAULT_GRIPHOME) + if not os.path.exists(instance_path): + instance_path = os.environ.get('XDG_CONFIG_HOME', '~/.config') + instance_path = os.path.join(instance_path, 'grip') instance_path = os.path.abspath(os.path.expanduser(instance_path)) # Flask application @@ -353,7 +356,9 @@ def default_asset_manager(self): cache_directory = self.config['CACHE_DIRECTORY'] if cache_directory: cache_directory = cache_directory.format(version=__version__) - cache_path = os.path.join(self.instance_path, cache_directory) + cache_path = os.environ.get('XDG_CACHE_HOME', '~/.cache') + cache_path = os.path.abspath(os.path.expanduser(cache_path)) + cache_path = os.path.join(cache_path, 'grip', cache_directory) return GitHubAssetManager( cache_path, self.config['STYLE_URLS'], self.quiet) diff --git a/grip/settings.py b/grip/settings.py index 7d8ba08..0a6e2bb 100644 --- a/grip/settings.py +++ b/grip/settings.py @@ -3,7 +3,10 @@ Do NOT change the values here for risk of accidentally committing them. Override them using command-line arguments or with a settings_local.py in -this directory or in ~/.grip/settings.py instead. +this directory or in one of the following (in order of precedence): + 1. "${GRIPHOME}/settings.py" (if GRIPHOME is set) + 2. "~/.grip/settings.py" (if "~/.grip" exists) + 3. "${XDG_CONFIG_HOME:-~/.config}/grip/settings.py" (fallback) """