use xdg dirs for config & data

~/.linkchecker is used instead of the xdg equivalents if the directory
exists (backward compatibility).
This commit is contained in:
Félix Sipma 2017-10-17 18:26:08 +02:00
parent 231dece9c4
commit a03e2e4ada
6 changed files with 17 additions and 6 deletions

View file

@ -17,6 +17,7 @@
import os import os
import sys import sys
from xdg import xdg_config_home
# Windows filename encoding # Windows filename encoding
nt_filename_encoding="mbcs" nt_filename_encoding="mbcs"
@ -40,7 +41,7 @@ def get_profile_dir ():
if sys.platform == 'darwin': if sys.platform == 'darwin':
dirpath = os.path.join(basedir, u"Library", u"Application Support") dirpath = os.path.join(basedir, u"Library", u"Application Support")
else: else:
dirpath = os.path.join(basedir, u".config") dirpath = xdg_config_home
dirpath = os.path.join(dirpath, u"Google", u"Chrome") dirpath = os.path.join(dirpath, u"Google", u"Chrome")
return dirpath return dirpath

View file

@ -18,6 +18,7 @@
import os import os
import sys import sys
import json import json
from xdg import xdg_config_home
# Windows filename encoding # Windows filename encoding
@ -42,7 +43,7 @@ def get_profile_dir ():
if sys.platform == 'darwin': if sys.platform == 'darwin':
dirpath = os.path.join(basedir, u"Library", u"Application Support") dirpath = os.path.join(basedir, u"Library", u"Application Support")
else: else:
dirpath = os.path.join(basedir, u".config") dirpath = xdg_config_home
dirpath = os.path.join(dirpath, u"chromium") dirpath = os.path.join(dirpath, u"chromium")
return dirpath return dirpath

View file

@ -32,6 +32,7 @@ import _LinkChecker_configdata as configdata
from .. import (log, LOG_CHECK, get_install_data, fileutil) from .. import (log, LOG_CHECK, get_install_data, fileutil)
from . import confparse from . import confparse
from ..decorators import memoized from ..decorators import memoized
from xdg.BaseDirectory import xdg_config_home, xdg_data_home
Version = configdata.version Version = configdata.version
ReleaseDate = configdata.release_date ReleaseDate = configdata.release_date
@ -365,9 +366,12 @@ class Configuration (dict):
def get_plugin_folders(): def get_plugin_folders():
"""Get linkchecker plugin folders. Default is ~/.linkchecker/plugins/.""" """Get linkchecker plugin folders. Default is
$XDG_DATA_HOME/linkchecker/plugins/."""
folders = [] 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: if not os.path.exists(defaultfolder) and not Portable:
try: try:
make_userdir(defaultfolder) make_userdir(defaultfolder)
@ -403,7 +407,9 @@ def get_user_config():
# initial config (with all options explained) # initial config (with all options explained)
initialconf = normpath(os.path.join(get_share_dir(), "linkcheckerrc")) initialconf = normpath(os.path.join(get_share_dir(), "linkcheckerrc"))
# per user config settings # 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 \ if os.path.isfile(initialconf) and not os.path.exists(userconf) and \
not Portable: not Portable:
# copy the initial configuration to the user configuration # copy the initial configuration to the user configuration

View file

@ -20,6 +20,7 @@ A blacklist logger.
import os import os
import codecs import codecs
from xdg.BaseDirectory import xdg_data_home
from . import _Logger from . import _Logger
@ -33,7 +34,7 @@ class BlacklistLogger (_Logger):
LoggerName = "blacklist" LoggerName = "blacklist"
LoggerArgs = { LoggerArgs = {
"filename": "~/.linkchecker/blacklist", "filename": os.path.join(xdg_data_home, "linkchecker", "blacklist"),
} }
def __init__ (self, **kwargs): def __init__ (self, **kwargs):

View file

@ -1,4 +1,5 @@
# required: # required:
requests<2.15,>=2.2 requests<2.15,>=2.2
xdg
# optional: # optional:
argcomplete argcomplete

View file

@ -481,6 +481,7 @@ args = dict(
# Requirements, usable with setuptools or the new Python packaging module. # Requirements, usable with setuptools or the new Python packaging module.
install_requires = [ install_requires = [
'requests<2.15,>=2.2', 'requests<2.15,>=2.2',
'xdg',
], ],
# Commented out since they are untested and not officially supported. # Commented out since they are untested and not officially supported.
# See also doc/install.txt for more detailed dependency documentation. # See also doc/install.txt for more detailed dependency documentation.