Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Gramps' core to be imported without requiring GObject #2016

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 46 additions & 39 deletions gramps/gen/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

LOG = logging.getLogger(".")

from gi.repository import GLib

# -------------------------------------------------------------------------
#
# Gramps modules
Expand Down Expand Up @@ -97,46 +95,55 @@
# Determine the user data and user configuration directories.
#
# -------------------------------------------------------------------------
if "GRAMPSHOME" in os.environ:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was deleted in error, and should be added back.

USER_HOME = get_env_var("GRAMPSHOME")
if "GRAMPSHOME_ISOLATED" in os.environ:
USER_HOME = get_env_var("GRAMPSHOME_ISOLATED")
USER_DATA = os.path.join(USER_HOME, "gramps")
USER_CONFIG = USER_DATA
elif "USERPROFILE" in os.environ:
USER_HOME = get_env_var("USERPROFILE")
if "APPDATA" in os.environ:
USER_DATA = os.path.join(get_env_var("APPDATA"), "gramps")
else:
USER_DATA = os.path.join(USER_HOME, "AppData", "Roaming", "gramps")
USER_CONFIG = USER_DATA
# Migrate data from AppData\Local to AppData\Roaming on Windows.
OLD_HOME = os.path.join(USER_HOME, "AppData", "Local", "gramps")
if os.path.exists(OLD_HOME):
if os.path.exists(USER_DATA):
LOG.warning("Two Gramps application data directories exist.")
else:
shutil.move(OLD_HOME, USER_DATA)
USER_CONFIG = os.path.join(USER_DATA, "config")
USER_CACHE = os.path.join(USER_DATA, "cache")
USER_PICTURES = os.path.join(USER_DATA, "pictures")
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")
# Copy the database directory into the XDG directory.
OLD_HOME = os.path.join(USER_HOME, ".gramps")
if os.path.exists(OLD_HOME):
if os.path.exists(USER_DATA) or os.path.exists(USER_CONFIG):
LOG.warning("Two Gramps application data directories exist.")
from gi.repository import GLib

if "GRAMPSHOME" in os.environ:
USER_HOME = get_env_var("GRAMPSHOME")
USER_DATA = os.path.join(USER_HOME, "gramps")
USER_CONFIG = USER_DATA
elif "USERPROFILE" in os.environ:
USER_HOME = get_env_var("USERPROFILE")
if "APPDATA" in os.environ:
USER_DATA = os.path.join(get_env_var("APPDATA"), "gramps")
else:
db_dir = os.path.join(OLD_HOME, "grampsdb")
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")

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

USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
if not USER_PICTURES:
USER_PICTURES = USER_DATA
USER_DATA = os.path.join(USER_HOME, "AppData", "Roaming", "gramps")
USER_CONFIG = USER_DATA
# Migrate data from AppData\Local to AppData\Roaming on Windows.
OLD_HOME = os.path.join(USER_HOME, "AppData", "Local", "gramps")
if os.path.exists(OLD_HOME):
if os.path.exists(USER_DATA):
LOG.warning("Two Gramps application data directories exist.")
else:
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")
# Copy the database directory into the XDG directory.
OLD_HOME = os.path.join(USER_HOME, ".gramps")
if os.path.exists(OLD_HOME):
if os.path.exists(USER_DATA) or os.path.exists(USER_CONFIG):
LOG.warning("Two Gramps application data directories exist.")
else:
db_dir = os.path.join(OLD_HOME, "grampsdb")
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")

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

USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
if not USER_PICTURES:
USER_PICTURES = USER_DATA

VERSION_DIR_NAME = "gramps%s%s" % (VERSION_TUPLE[0], VERSION_TUPLE[1])
VERSION_DIR = os.path.join(USER_CONFIG, VERSION_DIR_NAME)
Expand Down
9 changes: 2 additions & 7 deletions gramps/gen/utils/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
# -------------------------------------------------------------------------
from importlib.util import find_spec

# -------------------------------------------------------------------------
#
# GTK modules
#
# -------------------------------------------------------------------------
import gi

# -------------------------------------------------------------------------
#
# Gramps modules
Expand Down Expand Up @@ -89,6 +82,8 @@ def _test_gi(self, module, version):
"""
Test to see if a particular version of a module is available.
"""
import gi

try:
gi.require_version(module, version)
return True
Expand Down