summaryrefslogtreecommitdiff
path: root/cliapp/settings.py
diff options
context:
space:
mode:
Diffstat (limited to 'cliapp/settings.py')
-rw-r--r--cliapp/settings.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/cliapp/settings.py b/cliapp/settings.py
index 1fe1a67..969600b 100644
--- a/cliapp/settings.py
+++ b/cliapp/settings.py
@@ -23,6 +23,13 @@ import sys
import yaml
+try:
+ import xdg.BaseDirectory
+except ImportError: # pragma: no cover
+ xdg_is_available = False
+else: # pragma: no cover
+ xdg_is_available = True
+
import cliapp
from cliapp.genman import ManpageGenerator
@@ -734,11 +741,25 @@ class Settings(object):
configs.append('/etc/%s.conf' % self.progname)
configs.append('/etc/%s.yaml' % self.progname)
configs += self.listconfs('/etc/%s' % self.progname)
+
configs.append(os.path.expanduser('~/.%s.conf' % self.progname))
configs.append(os.path.expanduser('~/.%s.yaml' % self.progname))
configs += self.listconfs(
os.path.expanduser('~/.config/%s' % self.progname))
+ # See <http://standards.freedesktop.org/basedir-spec/>. We
+ # support these if the xdg library is available. We always
+ # support the hardcoded locations so that people's config
+ # files don't get ignored just because the xdg library gets
+ # installed.
+
+ if xdg_is_available: # pragma: no cover
+ for dirname in reversed(xdg.BaseDirectory.xdg_config_dirs):
+ pathname = os.path.join(dirname, self.progname)
+ for location in self.listconfs(pathname):
+ if location not in configs:
+ configs.append(location)
+
return configs
def listconfs(self, dirname, listdir=os.listdir):