From a03e2e4ada97f12f03c70776ccfe28867d5381f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Sipma?= Date: Tue, 17 Oct 2017 18:26:08 +0200 Subject: [PATCH 1/6] use xdg dirs for config & data ~/.linkchecker is used instead of the xdg equivalents if the directory exists (backward compatibility). --- linkcheck/bookmarks/chrome.py | 3 ++- linkcheck/bookmarks/chromium.py | 3 ++- linkcheck/configuration/__init__.py | 12 +++++++++--- linkcheck/logger/blacklist.py | 3 ++- requirements.txt | 1 + setup.py | 1 + 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/linkcheck/bookmarks/chrome.py b/linkcheck/bookmarks/chrome.py index 39885d09..05a011e0 100644 --- a/linkcheck/bookmarks/chrome.py +++ b/linkcheck/bookmarks/chrome.py @@ -17,6 +17,7 @@ import os import sys +from xdg import xdg_config_home # Windows filename encoding nt_filename_encoding="mbcs" @@ -40,7 +41,7 @@ def get_profile_dir (): if sys.platform == 'darwin': dirpath = os.path.join(basedir, u"Library", u"Application Support") else: - dirpath = os.path.join(basedir, u".config") + dirpath = xdg_config_home dirpath = os.path.join(dirpath, u"Google", u"Chrome") return dirpath diff --git a/linkcheck/bookmarks/chromium.py b/linkcheck/bookmarks/chromium.py index 31fb8b8b..521eb4ab 100644 --- a/linkcheck/bookmarks/chromium.py +++ b/linkcheck/bookmarks/chromium.py @@ -18,6 +18,7 @@ import os import sys import json +from xdg import xdg_config_home # Windows filename encoding @@ -42,7 +43,7 @@ def get_profile_dir (): if sys.platform == 'darwin': dirpath = os.path.join(basedir, u"Library", u"Application Support") else: - dirpath = os.path.join(basedir, u".config") + dirpath = xdg_config_home dirpath = os.path.join(dirpath, u"chromium") return dirpath diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 4bcb7de4..7ee566e0 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -32,6 +32,7 @@ import _LinkChecker_configdata as configdata from .. import (log, LOG_CHECK, get_install_data, fileutil) from . import confparse from ..decorators import memoized +from xdg.BaseDirectory import xdg_config_home, xdg_data_home Version = configdata.version ReleaseDate = configdata.release_date @@ -365,9 +366,12 @@ class Configuration (dict): def get_plugin_folders(): - """Get linkchecker plugin folders. Default is ~/.linkchecker/plugins/.""" + """Get linkchecker plugin folders. Default is + $XDG_DATA_HOME/linkchecker/plugins/.""" folders = [] - defaultfolder = normpath("~/.linkchecker/plugins") + homedotfilefolder = normpath("~/.linkchecker/plugins") + defaultfolder = homedotfilefolder if os.path.isdir(homedotfilefolder) \ + else os.path.join(xdg_data_home, "linkchecker", "plugins") if not os.path.exists(defaultfolder) and not Portable: try: make_userdir(defaultfolder) @@ -403,7 +407,9 @@ def get_user_config(): # initial config (with all options explained) initialconf = normpath(os.path.join(get_share_dir(), "linkcheckerrc")) # per user config settings - userconf = normpath("~/.linkchecker/linkcheckerrc") + homedotfile = normpath("~/.linkchecker/linkcheckerrc") + userconf = homedotfile if os.path.isfile(homedotfile) \ + else os.path.join(xdg_config_home, "linkchecker", "linkcheckerrc") if os.path.isfile(initialconf) and not os.path.exists(userconf) and \ not Portable: # copy the initial configuration to the user configuration diff --git a/linkcheck/logger/blacklist.py b/linkcheck/logger/blacklist.py index e4174c67..63755c74 100644 --- a/linkcheck/logger/blacklist.py +++ b/linkcheck/logger/blacklist.py @@ -20,6 +20,7 @@ A blacklist logger. import os import codecs +from xdg.BaseDirectory import xdg_data_home from . import _Logger @@ -33,7 +34,7 @@ class BlacklistLogger (_Logger): LoggerName = "blacklist" LoggerArgs = { - "filename": "~/.linkchecker/blacklist", + "filename": os.path.join(xdg_data_home, "linkchecker", "blacklist"), } def __init__ (self, **kwargs): diff --git a/requirements.txt b/requirements.txt index 84148800..5b9cc6dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ # required: requests<2.15,>=2.2 +xdg # optional: argcomplete diff --git a/setup.py b/setup.py index 73ac6f34..eaf86661 100755 --- a/setup.py +++ b/setup.py @@ -481,6 +481,7 @@ args = dict( # Requirements, usable with setuptools or the new Python packaging module. install_requires = [ 'requests<2.15,>=2.2', + 'xdg', ], # Commented out since they are untested and not officially supported. # See also doc/install.txt for more detailed dependency documentation. From 0a6661d1717335a586637466c9282629fdc6028d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Sipma?= Date: Wed, 18 Oct 2017 12:11:01 +0200 Subject: [PATCH 2/6] use pyxdg instead of xdg --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5b9cc6dc..9966e26b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # required: requests<2.15,>=2.2 -xdg +pyxdg # optional: argcomplete diff --git a/setup.py b/setup.py index eaf86661..42cfed86 100755 --- a/setup.py +++ b/setup.py @@ -481,7 +481,7 @@ args = dict( # Requirements, usable with setuptools or the new Python packaging module. install_requires = [ 'requests<2.15,>=2.2', - 'xdg', + 'pyxdg', ], # Commented out since they are untested and not officially supported. # See also doc/install.txt for more detailed dependency documentation. From deca8c667e90e8eb57b8de6b3bf7e8c55d5328c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Sipma?= Date: Wed, 18 Oct 2017 15:55:31 +0200 Subject: [PATCH 3/6] introduce linkcheck.configuration.get_user_data() --- linkcheck/configuration/__init__.py | 15 ++++++++++++--- linkcheck/logger/blacklist.py | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 7ee566e0..895a06b2 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -365,13 +365,22 @@ class Configuration (dict): pass +def get_user_data(): + """Get the user data folder. + Returns "~/.linkchecker/" if this folder exists, \ + "$XDG_DATA_HOME/linkchecker" if it does not. + @rtype string + """ + homedotdir = normpath("~/.linkchecker/") + userdata = homedotdir if os.path.isdir(homedotdir) \ + else os.path.join(xdg_data_home, "linkchecker") + return userdata + def get_plugin_folders(): """Get linkchecker plugin folders. Default is $XDG_DATA_HOME/linkchecker/plugins/.""" folders = [] - homedotfilefolder = normpath("~/.linkchecker/plugins") - defaultfolder = homedotfilefolder if os.path.isdir(homedotfilefolder) \ - else os.path.join(xdg_data_home, "linkchecker", "plugins") + defaultfolder = os.path.join(get_user_data(), "plugins") if not os.path.exists(defaultfolder) and not Portable: try: make_userdir(defaultfolder) diff --git a/linkcheck/logger/blacklist.py b/linkcheck/logger/blacklist.py index 63755c74..450226a5 100644 --- a/linkcheck/logger/blacklist.py +++ b/linkcheck/logger/blacklist.py @@ -20,7 +20,7 @@ A blacklist logger. import os import codecs -from xdg.BaseDirectory import xdg_data_home +from linkcheck.configuration import get_user_data from . import _Logger @@ -34,7 +34,7 @@ class BlacklistLogger (_Logger): LoggerName = "blacklist" LoggerArgs = { - "filename": os.path.join(xdg_data_home, "linkchecker", "blacklist"), + "filename": os.path.join(get_user_data(), "blacklist"), } def __init__ (self, **kwargs): From c8d9038ae880acc03c764ee01af77a8059bc5c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Sipma?= Date: Wed, 18 Oct 2017 15:58:18 +0200 Subject: [PATCH 4/6] improve get_plugin_folders() docstring --- linkcheck/configuration/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 895a06b2..87141dc6 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -378,7 +378,9 @@ def get_user_data(): def get_plugin_folders(): """Get linkchecker plugin folders. Default is - $XDG_DATA_HOME/linkchecker/plugins/.""" + "$XDG_DATA_HOME/linkchecker/plugins/". "~/.linkchecker/plugins/" is also + supported for backwards compatibility, and is used if both directories + exist.""" folders = [] defaultfolder = os.path.join(get_user_data(), "plugins") if not os.path.exists(defaultfolder) and not Portable: From 7344a3c40b1382966800ad56cb9d3933297bab9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Sipma?= Date: Wed, 18 Oct 2017 16:02:56 +0200 Subject: [PATCH 5/6] update changelog --- doc/changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/changelog.txt b/doc/changelog.txt index 7d5ec649..c8f6a8de 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -3,6 +3,8 @@ Features: - checking: Support itms-services: URLs. Closes: GH bug #532 +- checking: Support XDG Base Directory Specification for configuration + and data. Changes: - installation: Remove dependency on msgfmt.py by pre-generating the From e94fd3b4d85f30ba6d226c4646cef9aa765b11a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Sipma?= Date: Wed, 18 Oct 2017 16:09:51 +0200 Subject: [PATCH 6/6] mention #44 in changelog entry --- doc/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog.txt b/doc/changelog.txt index c8f6a8de..98969d73 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -5,6 +5,7 @@ Features: Closes: GH bug #532 - checking: Support XDG Base Directory Specification for configuration and data. + Closes: GH bug #44 Changes: - installation: Remove dependency on msgfmt.py by pre-generating the