From 6e58d6791c87e59224d78dbde0d0dd6c73ed37f2 Mon Sep 17 00:00:00 2001 From: c4llv07e Date: Wed, 30 Aug 2023 09:30:26 +0300 Subject: [PATCH 1/3] Use XDG standard by default Signed-off-by: c4llv07e --- tg/config.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tg/config.py b/tg/config.py index 4d02df1..ccdd63c 100644 --- a/tg/config.py +++ b/tg/config.py @@ -11,14 +11,16 @@ _darwin = "Darwin" _linux = "Linux" +def expand_path(path): + return os.path.expandvars(os.path.expanduser(path)) -CONFIG_DIR = os.path.expanduser("~/.config/tg/") +CONFIG_DIR = expand_path("$XDG_CONFIG_HOME/tg/") CONFIG_FILE = os.path.join(CONFIG_DIR, "conf.py") -FILES_DIR = os.path.expanduser("~/.cache/tg/") +FILES_DIR = expand_path("$XDG_CACHE_HOME/tg/") MAILCAP_FILE: Optional[str] = None LOG_LEVEL = "INFO" -LOG_PATH = os.path.expanduser("~/.local/share/tg/") +LOG_PATH = expand_path("$XDG_DATA_HOME/tg/") API_ID = "559815" API_HASH = "fd121358f59d764c57c55871aa0807ca" @@ -78,7 +80,7 @@ FILE_PICKER_CMD = "ranger --choosefile={file_path}" -DOWNLOAD_DIR = os.path.expanduser("~/Downloads/") +DOWNLOAD_DIR = expand_path("$XDG_DOWNLOAD_DIR") if os.path.isfile(CONFIG_FILE): config_params = runpy.run_path(CONFIG_FILE) # type: ignore From 1eeeb288cf5c4a98ea0b592e7517bac6b4565e3a Mon Sep 17 00:00:00 2001 From: c4llv07e Date: Fri, 1 Sep 2023 06:19:50 +0300 Subject: [PATCH 2/3] Fallback to default directories if XDG is not set Signed-off-by: c4llv07e --- tg/config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tg/config.py b/tg/config.py index ccdd63c..c84d461 100644 --- a/tg/config.py +++ b/tg/config.py @@ -14,13 +14,18 @@ def expand_path(path): return os.path.expandvars(os.path.expanduser(path)) -CONFIG_DIR = expand_path("$XDG_CONFIG_HOME/tg/") +CONFIG_HOME = expand_path(os.getenv("XDG_CONFIG_HOME", "~/.config")) +CACHE_HOME = expand_path(os.getenv("XDG_CACHE_HOME", "~/.cache")) +DATA_HOME = expand_path(os.getenv("XD_GDATA_HOME", "~/.local/share")) +DOWNLOAD_DIR = expand_path(os.getenv("XDG_DOWNLOAD_DIR", "~/Downloads")) + +CONFIG_DIR = os.path.join(CONFIG_HOME, "tg/") CONFIG_FILE = os.path.join(CONFIG_DIR, "conf.py") -FILES_DIR = expand_path("$XDG_CACHE_HOME/tg/") +FILES_DIR = os.path.join(CACHE_HOME, "tg/") MAILCAP_FILE: Optional[str] = None LOG_LEVEL = "INFO" -LOG_PATH = expand_path("$XDG_DATA_HOME/tg/") +LOG_PATH = expand_path(DATA_HOME + "/tg/") API_ID = "559815" API_HASH = "fd121358f59d764c57c55871aa0807ca" @@ -80,8 +85,6 @@ def expand_path(path): FILE_PICKER_CMD = "ranger --choosefile={file_path}" -DOWNLOAD_DIR = expand_path("$XDG_DOWNLOAD_DIR") - if os.path.isfile(CONFIG_FILE): config_params = runpy.run_path(CONFIG_FILE) # type: ignore for param, value in config_params.items(): From 1cdeba5b36068b74ca478df70c5a639acd98eeea Mon Sep 17 00:00:00 2001 From: c4llv07e <38111072+c4llv07e@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:30:04 +0000 Subject: [PATCH 3/3] fix XDG variable name Co-authored-by: arza --- tg/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tg/config.py b/tg/config.py index c84d461..e894f1f 100644 --- a/tg/config.py +++ b/tg/config.py @@ -16,7 +16,7 @@ def expand_path(path): CONFIG_HOME = expand_path(os.getenv("XDG_CONFIG_HOME", "~/.config")) CACHE_HOME = expand_path(os.getenv("XDG_CACHE_HOME", "~/.cache")) -DATA_HOME = expand_path(os.getenv("XD_GDATA_HOME", "~/.local/share")) +DATA_HOME = expand_path(os.getenv("XDG_DATA_HOME", "~/.local/share")) DOWNLOAD_DIR = expand_path(os.getenv("XDG_DOWNLOAD_DIR", "~/Downloads")) CONFIG_DIR = os.path.join(CONFIG_HOME, "tg/")