PICARD-2189: Add appdirs module to fix getting proper cache location

The cache location previously was wrong because it was created before app and org name had been set. The new module fixes this and allows more flexible replacement of the implementation.
This commit is contained in:
Philipp Wolfer
2021-06-29 17:54:00 +02:00
parent 2422d74cb3
commit f53a35eee6
5 changed files with 139 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ from picard import (
PICARD_ORG_NAME,
)
import picard.const
import picard.const.appdirs
# The portable version stores all data in a folder beside the executable
@@ -41,9 +42,13 @@ if '--config-file' not in sys.argv and '-c' not in sys.argv:
sys.argv.append(os.path.join(basedir, 'Config.ini'))
# Setup plugin folder
picard.const.USER_PLUGIN_DIR = os.path.normpath(os.path.join(basedir, 'Plugins'))
plugindir = os.path.normpath(os.path.join(basedir, 'Plugins'))
picard.const.USER_PLUGIN_DIR = plugindir
# Set standard cache location
cachedir = os.path.normpath(os.path.join(basedir, 'Cache'))
os.makedirs(cachedir, exist_ok=True)
picard.const.CACHE_DIR = cachedir
picard.const.appdirs.config_folder = lambda: basedir
picard.const.appdirs.cache_folder = lambda: cachedir
picard.const.appdirs.plugin_folder = lambda: plugindir