summaryrefslogtreecommitdiff
path: root/cliapp
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-12-27 19:41:51 +0100
committerLars Wirzenius <liw@liw.fi>2015-12-27 19:41:51 +0100
commit6b11572afcaa1ba9003ee8bf49adb4529e0f1188 (patch)
tree3e7e4fdaed506b231323f68d8e5ca33d4a8d6992 /cliapp
parent7e8d31fa8adba20a21c13c1d4a261fb0a815e6c5 (diff)
downloadcliapp-6b11572afcaa1ba9003ee8bf49adb4529e0f1188.tar.gz
Add XDG Base Directory specification support
Diffstat (limited to 'cliapp')
-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):