use get_user_dir (#3549)

kaalleen/test-to-satin-distance
Kaalleen 2025-03-04 09:56:51 +01:00 zatwierdzone przez GitHub
rodzic bef98ef4eb
commit f672d71335
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
6 zmienionych plików z 22 dodań i 39 usunięć

Wyświetl plik

@ -6,10 +6,10 @@
import json
import os
import platformdirs
from inkex import errormsg
from ..i18n import _
from ..utils import get_user_dir
from .base import InkstitchExtension
@ -30,20 +30,13 @@ class LetteringCustomFontDir(InkstitchExtension):
data = {'custom_font_dir': '%s' % path}
try:
config_path = platformdirs.user_config_dir('inkstitch')
except ImportError:
config_path = os.path.expanduser('~/.inkstitch')
if not os.path.exists(config_path):
os.makedirs(config_path)
config_path = os.path.join(config_path, 'custom_dirs.json')
config_path = get_user_dir('custom_dirs.json')
with open(config_path, 'w', encoding="utf8") as font_data:
json.dump(data, font_data, indent=4, ensure_ascii=False)
def get_custom_font_dir():
custom_font_dir_path = os.path.join(platformdirs.user_config_dir('inkstitch'), 'custom_dirs.json')
custom_font_dir_path = get_user_dir('custom_dirs.json')
try:
with open(custom_font_dir_path, 'r') as custom_dirs:
custom_dir = json.load(custom_dirs)

Wyświetl plik

@ -14,7 +14,6 @@ from copy import deepcopy
from datetime import date
from threading import Thread
import platformdirs
import wx
from flask import Flask, Response, jsonify, request, send_from_directory
from jinja2 import Environment, FileSystemLoader, select_autoescape
@ -27,7 +26,7 @@ from ..i18n import translation as inkstitch_translation
from ..stitch_plan import stitch_groups_to_stitch_plan
from ..svg import render_stitch_plan
from ..threads import ThreadCatalog
from ..utils import get_resource_dir
from ..utils import get_resource_dir, get_user_dir
from .base import InkstitchExtension
@ -36,12 +35,7 @@ def datetimeformat(value, format='%Y/%m/%d'):
def defaults_path():
defaults_dir = platformdirs.user_config_dir('inkstitch')
if not os.path.exists(defaults_dir):
os.makedirs(defaults_dir)
return os.path.join(defaults_dir, 'print_settings.json')
return get_user_dir('print_settings.json')
def load_defaults():

Wyświetl plik

@ -4,13 +4,12 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import json
import os
import re
import wx
from ..i18n import _
from ..utils import cache
from ..utils import cache, get_user_dir
from .dialogs import info_dialog
@ -88,15 +87,7 @@ class PresetsPanel(wx.Panel):
@cache
def presets_path(self):
try:
import platformdirs
config_path = platformdirs.user_config_dir('inkstitch')
except ImportError:
config_path = os.path.expanduser('~/.inkstitch')
if not os.path.exists(config_path):
os.makedirs(config_path)
return os.path.join(config_path, '%s.json' % self.suite_name)
return get_user_dir(f'{self.suite_name}.json')
def _load_presets(self):
try:

Wyświetl plik

@ -5,11 +5,9 @@
import os
import platformdirs
from ..extensions.lettering_custom_font_dir import get_custom_font_dir
from ..lettering import Font
from ..utils import get_bundled_dir
from ..utils import get_bundled_dir, get_user_dir
def get_font_list():
@ -36,7 +34,7 @@ def get_font_paths():
font_paths = {
get_bundled_dir("fonts"),
os.path.expanduser("~/.inkstitch/fonts"),
os.path.join(platformdirs.user_config_dir('inkstitch'), 'fonts'),
get_user_dir('fonts'),
get_custom_font_dir()
}
return font_paths

Wyświetl plik

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

Wyświetl plik

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