summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2025-03-04 09:56:51 +0100
committerGitHub <noreply@github.com>2025-03-04 09:56:51 +0100
commitf672d713351ade5dbd8f593bf4b329fb19ad8168 (patch)
treeececdabdf59f2263c40ffbd4edb0ff4f4f397b0c /lib/utils
parentbef98ef4ebb5af247f349e32f55a6648bf9dbceb (diff)
use get_user_dir (#3549)
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/cache.py12
-rwxr-xr-xlib/utils/paths.py7
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/utils/cache.py b/lib/utils/cache.py
index 76ce2416..18f993e9 100644
--- a/lib/utils/cache.py
+++ b/lib/utils/cache.py
@@ -8,11 +8,12 @@ import os
import pickle
import sqlite3
-import platformdirs
import diskcache
from lib.utils.settings import global_settings
+from .paths import get_user_dir
+
try:
from functools import lru_cache
except ImportError:
@@ -31,16 +32,17 @@ def get_stitch_plan_cache():
global __stitch_plan_cache
if __stitch_plan_cache is None:
- cache_dir = os.path.join(platformdirs.user_config_dir('inkstitch'), 'cache', 'stitch_plan')
+ cache_dir = get_user_dir('cache')
+ stitch_plan_dir = os.path.join(cache_dir, 'stitch_plan')
size_limit = global_settings['cache_size'] * 1024 * 1024
try:
- __stitch_plan_cache = diskcache.Cache(cache_dir, size=size_limit)
+ __stitch_plan_cache = diskcache.Cache(stitch_plan_dir, size=size_limit)
except (sqlite3.DatabaseError, sqlite3.OperationalError):
# reset cache database file if it couldn't parse correctly
- cache_file = os.path.join(platformdirs.user_config_dir('inkstitch'), 'cache', 'stitch_plan', 'cache.db')
+ cache_file = os.path.join(stitch_plan_dir, 'cache.db')
if os.path.exists(cache_file):
os.remove(cache_file)
- __stitch_plan_cache = diskcache.Cache(cache_dir, size=size_limit)
+ __stitch_plan_cache = diskcache.Cache(stitch_plan_dir, size=size_limit)
__stitch_plan_cache.size_limit = size_limit
# reset cache if warnings appear within the files
diff --git a/lib/utils/paths.py b/lib/utils/paths.py
index 6eafbd77..3bc12c2a 100755
--- a/lib/utils/paths.py
+++ b/lib/utils/paths.py
@@ -42,7 +42,12 @@ def get_resource_dir(name):
def get_user_dir(name=None):
- path = platformdirs.user_config_dir("inkstitch")
+ try:
+ path = platformdirs.user_config_dir('inkstitch')
+ except ImportError:
+ path = os.path.expanduser('~/.inkstitch')
+ if not os.path.exists(path):
+ os.makedirs(path)
if name is not None:
path = os.path.join(path, name)