Skip to content

Commit 1c4e62b

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

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

gramps/gen/const.py

+46-39
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
LOG = logging.getLogger(".")
4141

42-
from gi.repository import GLib
43-
4442
# -------------------------------------------------------------------------
4543
#
4644
# Gramps modules
@@ -97,46 +95,55 @@
9795
# Determine the user data and user configuration directories.
9896
#
9997
# -------------------------------------------------------------------------
100-
if "GRAMPSHOME" in os.environ:
101-
USER_HOME = get_env_var("GRAMPSHOME")
98+
if "GRAMPSHOME_ISOLATED" in os.environ:
99+
USER_HOME = get_env_var("GRAMPSHOME_ISOLATED")
102100
USER_DATA = os.path.join(USER_HOME, "gramps")
103-
USER_CONFIG = USER_DATA
104-
elif "USERPROFILE" in os.environ:
105-
USER_HOME = get_env_var("USERPROFILE")
106-
if "APPDATA" in os.environ:
107-
USER_DATA = os.path.join(get_env_var("APPDATA"), "gramps")
108-
else:
109-
USER_DATA = os.path.join(USER_HOME, "AppData", "Roaming", "gramps")
110-
USER_CONFIG = USER_DATA
111-
# Migrate data from AppData\Local to AppData\Roaming on Windows.
112-
OLD_HOME = os.path.join(USER_HOME, "AppData", "Local", "gramps")
113-
if os.path.exists(OLD_HOME):
114-
if os.path.exists(USER_DATA):
115-
LOG.warning("Two Gramps application data directories exist.")
116-
else:
117-
shutil.move(OLD_HOME, USER_DATA)
101+
USER_CONFIG = os.path.join(USER_DATA, "config")
102+
USER_CACHE = os.path.join(USER_DATA, "cache")
103+
USER_PICTURES = os.path.join(USER_DATA, "pictures")
118104
else:
119-
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")
122-
# Copy the database directory into the XDG directory.
123-
OLD_HOME = os.path.join(USER_HOME, ".gramps")
124-
if os.path.exists(OLD_HOME):
125-
if os.path.exists(USER_DATA) or os.path.exists(USER_CONFIG):
126-
LOG.warning("Two Gramps application data directories exist.")
105+
from gi.repository import GLib
106+
107+
if "GRAMPSHOME" in os.environ:
108+
USER_HOME = get_env_var("GRAMPSHOME")
109+
USER_DATA = os.path.join(USER_HOME, "gramps")
110+
USER_CONFIG = USER_DATA
111+
elif "USERPROFILE" in os.environ:
112+
USER_HOME = get_env_var("USERPROFILE")
113+
if "APPDATA" in os.environ:
114+
USER_DATA = os.path.join(get_env_var("APPDATA"), "gramps")
127115
else:
128-
db_dir = os.path.join(OLD_HOME, "grampsdb")
129-
if os.path.exists(db_dir):
130-
shutil.copytree(db_dir, os.path.join(USER_DATA, "grampsdb"))
131-
132-
USER_CACHE = os.path.join(GLib.get_user_cache_dir(), "gramps")
133-
134-
if "SAFEMODE" in os.environ:
135-
USER_CONFIG = get_env_var("SAFEMODE")
136-
137-
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
138-
if not USER_PICTURES:
139-
USER_PICTURES = USER_DATA
116+
USER_DATA = os.path.join(USER_HOME, "AppData", "Roaming", "gramps")
117+
USER_CONFIG = USER_DATA
118+
# Migrate data from AppData\Local to AppData\Roaming on Windows.
119+
OLD_HOME = os.path.join(USER_HOME, "AppData", "Local", "gramps")
120+
if os.path.exists(OLD_HOME):
121+
if os.path.exists(USER_DATA):
122+
LOG.warning("Two Gramps application data directories exist.")
123+
else:
124+
shutil.move(OLD_HOME, USER_DATA)
125+
else:
126+
USER_HOME = get_env_var("HOME")
127+
USER_DATA = os.path.join(GLib.get_user_data_dir(), "gramps")
128+
USER_CONFIG = os.path.join(GLib.get_user_config_dir(), "gramps")
129+
# Copy the database directory into the XDG directory.
130+
OLD_HOME = os.path.join(USER_HOME, ".gramps")
131+
if os.path.exists(OLD_HOME):
132+
if os.path.exists(USER_DATA) or os.path.exists(USER_CONFIG):
133+
LOG.warning("Two Gramps application data directories exist.")
134+
else:
135+
db_dir = os.path.join(OLD_HOME, "grampsdb")
136+
if os.path.exists(db_dir):
137+
shutil.copytree(db_dir, os.path.join(USER_DATA, "grampsdb"))
138+
139+
USER_CACHE = os.path.join(GLib.get_user_cache_dir(), "gramps")
140+
141+
if "SAFEMODE" in os.environ:
142+
USER_CONFIG = get_env_var("SAFEMODE")
143+
144+
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
145+
if not USER_PICTURES:
146+
USER_PICTURES = USER_DATA
140147

141148
VERSION_DIR_NAME = "gramps%s%s" % (VERSION_TUPLE[0], VERSION_TUPLE[1])
142149
VERSION_DIR = os.path.join(USER_CONFIG, VERSION_DIR_NAME)

gramps/gen/utils/requirements.py

+2-7
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
@@ -89,6 +82,8 @@ def _test_gi(self, module, version):
8982
"""
9083
Test to see if a particular version of a module is available.
9184
"""
85+
import gi
86+
9287
try:
9388
gi.require_version(module, version)
9489
return True

0 commit comments

Comments
 (0)