PICARD-118: Set cache location to portable config dir

This commit is contained in:
Philipp Wolfer
2019-10-14 10:44:41 +02:00
committed by Philipp Wolfer
parent 02cf4cddc0
commit ebfd17574a
3 changed files with 11 additions and 5 deletions

View File

@@ -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'

View File

@@ -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",

View File

@@ -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