From 921bb75c05764d446a486349cfe0ebcf8840a641 Mon Sep 17 00:00:00 2001 From: GeraldJansen Date: Wed, 4 Oct 2023 11:19:23 +0200 Subject: [PATCH] Remove python3-xdg dependency Use GLib functions get_user_config_dir and get_user_data_dir instead of pyxdg functions. One less dependency, yay. --- README.rst | 4 ++-- src/hamster_lite/lib/configuration.py | 5 ++--- src/hamster_lite/lib/runtime.py | 4 ++-- src/hamster_lite/storage.py | 9 ++------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index 1d80391..7b160b7 100644 --- a/README.rst +++ b/README.rst @@ -44,14 +44,14 @@ Debian-based (tested in Ubuntu 19.04) .. code:: bash - sudo apt install gettext intltool python3-gi-cairo python3-distutils python3-xdg + sudo apt install gettext intltool python3-gi-cairo python3-distutils Other ^^^^^ Current (late 2019) dependencies for `Hamster `__ -should work, keeping in mind that the dbus and gconf or gsettings/dconf dependencies are not +should work, keeping in mind that the dbus and gconf or gsettings/dconf dependencies are not needed. Trying the development version diff --git a/src/hamster_lite/lib/configuration.py b/src/hamster_lite/lib/configuration.py index bcc9064..46731c8 100644 --- a/src/hamster_lite/lib/configuration.py +++ b/src/hamster_lite/lib/configuration.py @@ -24,8 +24,7 @@ import os import json import datetime as dt -from xdg.BaseDirectory import xdg_data_home, xdg_config_home - +from gi.repository import GLib as glib class Singleton(object): def __new__(cls, *args, **kwargs): @@ -45,7 +44,7 @@ class ConfStore(Singleton): def __init__(self): self.config = self.DEFAULTS - config_dir = os.path.join(xdg_config_home, 'hamster-lite') + config_dir = os.path.join(glib.get_user_config_dir(), 'hamster-lite') if not os.path.exists(config_dir): os.makedirs(config_dir) self.config_file = os.path.join(config_dir, 'hamster-lite.json') diff --git a/src/hamster_lite/lib/runtime.py b/src/hamster_lite/lib/runtime.py index 81cfd81..a6fd57f 100644 --- a/src/hamster_lite/lib/runtime.py +++ b/src/hamster_lite/lib/runtime.py @@ -26,7 +26,7 @@ import datetime as dt from gi.repository import GObject as gobject from gi.repository import Gtk as gtk -from xdg.BaseDirectory import xdg_data_home, xdg_config_home +from gi.repository import GLib as glib import hamster_lite import hamster_lite.storage as db @@ -105,7 +105,7 @@ def __init__(self): self.data_dir = os.path.realpath(self.data_dir) self.home_data_dir = os.path.realpath( - os.path.join(xdg_data_home, "hamster-lite")) + os.path.join(glib.get_user_data_dir(), "hamster-lite")) self.storage = db.Storage() diff --git a/src/hamster_lite/storage.py b/src/hamster_lite/storage.py index dbfc343..c839a22 100644 --- a/src/hamster_lite/storage.py +++ b/src/hamster_lite/storage.py @@ -60,13 +60,8 @@ def __init__(self, unsorted="", database_dir=None): def __init_db_file(self, database_dir): if not database_dir: - try: - from xdg.BaseDirectory import xdg_data_home - except ImportError: - logger.warning( - "Could not import xdg - assuming ~/.local/share") - xdg_data_home = os.path.join(os.path.expanduser('~'), - '.local', 'share') + from gi.repository import GLib + xdg_data_home = GLib.get_user_data_dir() database_dir = os.path.join(xdg_data_home, 'hamster-lite') if not os.path.exists(database_dir):