From ebfd17574ab9bbf65364d264b7c8e80fd2d96ea4 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Mon, 14 Oct 2019 10:44:41 +0200 Subject: [PATCH] PICARD-118: Set cache location to portable config dir --- picard/const/__init__.py | 3 +++ picard/webservice/__init__.py | 5 ++--- scripts/picard-portable-hook.py | 8 ++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/picard/const/__init__.py b/picard/const/__init__.py index 8c5812000..bbea7551e 100644 --- a/picard/const/__init__.py +++ b/picard/const/__init__.py @@ -33,6 +33,9 @@ _appconfiglocation = QStandardPaths.writableLocation(QStandardPaths.AppConfigLoc USER_DIR = os.path.join(_appconfiglocation, "MusicBrainz", PICARD_APP_NAME) USER_PLUGIN_DIR = os.path.join(USER_DIR, "plugins") +# Cache directory +CACHE_DIR = QStandardPaths.writableLocation(QStandardPaths.CacheLocation) + # AcoustID client API key ACOUSTID_KEY = 'v8pQ6oyB' ACOUSTID_HOST = 'api.acoustid.org' diff --git a/picard/webservice/__init__.py b/picard/webservice/__init__.py index 1ef43ae23..212eb3262 100644 --- a/picard/webservice/__init__.py +++ b/picard/webservice/__init__.py @@ -39,7 +39,6 @@ from PyQt5 import ( QtNetwork, ) from PyQt5.QtCore import ( - QStandardPaths, QUrl, QUrlQuery, ) @@ -52,6 +51,7 @@ from picard import ( config, log, ) +from picard.const import CACHE_DIR from picard.oauth import OAuthManager from picard.util import ( build_qurl, @@ -288,8 +288,7 @@ class WebService(QtCore.QObject): def set_cache(self, cache_size_in_mb=100): cache = QtNetwork.QNetworkDiskCache() - location = QStandardPaths.writableLocation(QStandardPaths.CacheLocation) - cache.setCacheDirectory(os.path.join(location, 'picard')) + cache.setCacheDirectory(os.path.join(CACHE_DIR, 'network')) cache.setMaximumCacheSize(cache_size_in_mb * 1024 * 1024) self.manager.setCache(cache) log.debug("NetworkDiskCache dir: %r size: %s / %s", diff --git a/scripts/picard-portable-hook.py b/scripts/picard-portable-hook.py index a3fc5e86d..46b75bbc7 100644 --- a/scripts/picard-portable-hook.py +++ b/scripts/picard-portable-hook.py @@ -12,8 +12,7 @@ import picard.const # The portable version stores all data in a folder beside the executable configdir = '{}-{}'.format(PICARD_ORG_NAME, PICARD_APP_NAME) basedir = os.path.join(os.path.dirname(sys.executable), configdir) -if not os.path.exists(basedir): - os.makedirs(basedir) +os.makedirs(basedir, exist_ok=True) # Setup config file if not specified as command line argument if '--config-file' not in sys.argv and '-c' not in sys.argv: @@ -22,3 +21,8 @@ if '--config-file' not in sys.argv and '-c' not in sys.argv: # Setup plugin folder picard.const.USER_PLUGIN_DIR = os.path.join(basedir, 'Plugins') + +# Set standard cache location +cachedir = os.path.join(basedir, 'Cache') +os.makedirs(cachedir, exist_ok=True) +picard.const.CACHE_DIR = cachedir