Skip to content

Commit b8c765b

Browse files
committed
Decouple the Gramps core from GObject
1 parent a67bfcd commit b8c765b

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

gramps/gen/const.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,43 @@
9292
APP_GENEWEB = "application/x-geneweb"
9393
APP_VCARD = ["text/x-vcard", "text/x-vcalendar"]
9494

95+
9596
# -------------------------------------------------------------------------
9697
#
9798
# Determine the user data and user configuration directories.
9899
#
99100
# -------------------------------------------------------------------------
101+
def _glib_get_home_dir() -> str:
102+
return GLib.get_home_dir()
103+
104+
105+
def _glib_get_user_cache_dir() -> str:
106+
if "XDG_CACHE_HOME" in os.environ and os.environ["XDG_CACHE_HOME"]:
107+
return os.environ["XDG_CACHE_HOME"]
108+
cache_dir = get_special_folder_internet_cache()
109+
if cache_dir:
110+
return cache_dir
111+
return os.path.join(_glib_get_home_dir(), ".cache")
112+
113+
114+
def _glib_get_user_config_dir() -> str:
115+
if "XDG_CONFIG_HOME" in os.environ and os.environ["XDG_CONFIG_HOME"]:
116+
return os.environ["XDG_CONFIG_HOME"]
117+
config_dir = get_special_folder_local_app_data()
118+
if config_dir:
119+
return config_dir
120+
return os.path.join(_glib_get_home_dir(), ".config")
121+
122+
123+
def _glib_get_user_data_dir() -> str:
124+
if "XDG_DATA_HOME" in os.environ and os.environ["XDG_DATA_HOME"]:
125+
return os.environ["XDG_DATA_HOME"]
126+
data_dir = get_special_folder_local_app_data()
127+
if data_dir:
128+
return data_dir
129+
return os.path.join(_glib_get_home_dir(), ".local", "share")
130+
131+
100132
if "GRAMPSHOME" in os.environ:
101133
USER_HOME = get_env_var("GRAMPSHOME")
102134
USER_DATA = os.path.join(USER_HOME, "gramps")
@@ -117,8 +149,8 @@
117149
shutil.move(OLD_HOME, USER_DATA)
118150
else:
119151
USER_HOME = get_env_var("HOME")
120-
USER_DATA = os.path.join(GLib.get_user_data_dir(), "gramps")
121-
USER_CONFIG = os.path.join(GLib.get_user_config_dir(), "gramps")
152+
USER_DATA = os.path.join(_glib_get_user_data_dir(), "gramps")
153+
USER_CONFIG = os.path.join(_glib_get_user_config_dir(), "gramps")
122154
# Copy the database directory into the XDG directory.
123155
OLD_HOME = os.path.join(USER_HOME, ".gramps")
124156
if os.path.exists(OLD_HOME):
@@ -129,7 +161,7 @@
129161
if os.path.exists(db_dir):
130162
shutil.copytree(db_dir, os.path.join(USER_DATA, "grampsdb"))
131163

132-
USER_CACHE = os.path.join(GLib.get_user_cache_dir(), "gramps")
164+
USER_CACHE = os.path.join(_glib_get_user_cache_dir(), "gramps")
133165

134166
if "SAFEMODE" in os.environ:
135167
USER_CONFIG = get_env_var("SAFEMODE")

gramps/gen/utils/requirements.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
# -------------------------------------------------------------------------
2626
from importlib.util import find_spec
2727

28-
# -------------------------------------------------------------------------
29-
#
30-
# GTK modules
31-
#
32-
# -------------------------------------------------------------------------
33-
import gi
34-
3528
# -------------------------------------------------------------------------
3629
#
3730
# Gramps modules
@@ -90,9 +83,11 @@ def _test_gi(self, module, version):
9083
Test to see if a particular version of a module is available.
9184
"""
9285
try:
86+
import gi
87+
9388
gi.require_version(module, version)
9489
return True
95-
except ValueError:
90+
except (ModuleNotFoundError, ValueError):
9691
return False
9792

9893
def check_exe(self, executable):

0 commit comments

Comments
 (0)