0
0
mirror of https://github.com/gramps-project/gramps synced 2025-10-05 23:52:46 +02:00

Decouple the core library code from GObject introspection

This commit is contained in:
Nick Hall
2025-09-27 20:44:06 +01:00
parent 1f026ea1a1
commit 5007d76023
3 changed files with 46 additions and 14 deletions

View File

@@ -38,19 +38,23 @@ import logging
LOG = logging.getLogger(".")
from gi.repository import GLib
# -------------------------------------------------------------------------
#
# Gramps modules
#
# -------------------------------------------------------------------------
from .git_revision import get_git_revision
from .constfunc import get_env_var
from .constfunc import (
get_env_var,
get_user_cache_dir,
get_user_config_dir,
get_user_data_dir,
)
from ..version import VERSION, VERSION_TUPLE, major_version, DEV_VERSION
from .utils.resourcepath import ResourcePath
from .utils.grampslocale import GrampsLocale
# -------------------------------------------------------------------------
#
# Gramps program name
@@ -116,8 +120,8 @@ elif "USERPROFILE" in os.environ:
shutil.move(OLD_HOME, USER_DATA)
else:
USER_HOME = get_env_var("HOME")
USER_DATA = os.path.join(GLib.get_user_data_dir(), "gramps")
USER_CONFIG = os.path.join(GLib.get_user_config_dir(), "gramps")
USER_DATA = os.path.join(get_user_data_dir(), "gramps")
USER_CONFIG = os.path.join(get_user_config_dir(), "gramps")
# Copy the database directory into the XDG directory.
OLD_HOME = os.path.join(USER_HOME, ".gramps")
if os.path.exists(OLD_HOME):
@@ -128,12 +132,12 @@ else:
if os.path.exists(db_dir):
shutil.copytree(db_dir, os.path.join(USER_DATA, "grampsdb"))
USER_CACHE = os.path.join(GLib.get_user_cache_dir(), "gramps")
USER_CACHE = os.path.join(get_user_cache_dir(), "gramps")
if "SAFEMODE" in os.environ:
USER_CONFIG = get_env_var("SAFEMODE")
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
USER_PICTURES = os.path.join(USER_HOME, "Pictures")
if not USER_PICTURES:
USER_PICTURES = USER_DATA

View File

@@ -174,3 +174,36 @@ def get_curr_dir():
native GetCurrentDirectory function to return a unicode cwd.
"""
return os.getcwd()
# -------------------------------------------------------------------------
#
# Functions that return base directories as described in the XDG base directory
# specification.
#
# -------------------------------------------------------------------------
def get_user_data_dir():
"""
Returns a base directory in which to store user-specific application data.
"""
if "XDG_DATA_HOME" in os.environ:
return get_env_var("XDG_DATA_HOME")
return os.path.join(get_env_var("HOME"), ".local", "share")
def get_user_config_dir():
"""
Returns a base directory in which to store user-specific configuration settings.
"""
if "XDG_CONFIG_HOME" in os.environ:
return get_env_var("XDG_CONFIG_HOME")
return os.path.join(get_env_var("HOME"), ".config")
def get_user_cache_dir():
"""
Returns a base directory in which to store temporary cached data.
"""
if "XDG_CACHE_HOME" in os.environ:
return get_env_var("XDG_CACHE_HOME")
return os.path.join(get_env_var("HOME"), ".cache")

View File

@@ -24,13 +24,6 @@
# -------------------------------------------------------------------------
from importlib.util import find_spec
# -------------------------------------------------------------------------
#
# GTK modules
#
# -------------------------------------------------------------------------
import gi
# -------------------------------------------------------------------------
#
# Gramps modules
@@ -88,6 +81,8 @@ class Requirements:
"""
Test to see if a particular version of a module is available.
"""
import gi
try:
gi.require_version(module, version)
return True