diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-12-27 19:41:51 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-12-27 19:41:51 +0100 |
commit | 6b11572afcaa1ba9003ee8bf49adb4529e0f1188 (patch) | |
tree | 3e7e4fdaed506b231323f68d8e5ca33d4a8d6992 | |
parent | 7e8d31fa8adba20a21c13c1d4a261fb0a815e6c5 (diff) | |
download | cliapp-6b11572afcaa1ba9003ee8bf49adb4529e0f1188.tar.gz |
Add XDG Base Directory specification support
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | cliapp.5 | 9 | ||||
-rw-r--r-- | cliapp/settings.py | 21 | ||||
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | debian/control | 2 |
5 files changed, 36 insertions, 1 deletions
@@ -21,6 +21,9 @@ New feature: * Configuration files may now also be in YAML format, if names with an `.yaml` suffix. +* If the `python-xdg` library is available, it is used to allow user + to specify locations of XDG Base Directory locations. + Version 1.20150829 ------------------ @@ -311,3 +311,12 @@ Per-user configuration file. .BR ~/.config/progname/*.conf More per-user configuration files. Again, ASCII sorted order. +.PP +In addition, the XDG Base Directory specification is followed, +if the Python +.B python-xdg +library is installed. +In that case, environment variables can be set to set additional location +in which files are search for. +The fixed names above are always search; +the XDG ones are search additionally. 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): diff --git a/debian/changelog b/debian/changelog index 9dcf237..fe5a897 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ python-cliapp (1.20151220-1) UNRELEASED; urgency=medium to correct the dependency package name. (Closes: #804268) * Adds hard dependency on python-yaml. debian/control updated accordingly. + * Adds an optional use of python-xdg to allow XDG Base Directory + specification support. (Closes: #677117) -- Lars Wirzenius <liw@liw.fi> Sun, 20 Dec 2015 15:53:30 +0100 diff --git a/debian/control b/debian/control index 6ce7417..efcf6d9 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ X-Python-Version: >= 2.6 Package: python-cliapp Architecture: all Depends: ${python:Depends}, ${misc:Depends}, python (>= 2.6), python-yaml -Suggests: libjs-jquery, libjs-underscore +Suggests: libjs-jquery, libjs-underscore, python-xdg Description: Python framework for Unix command line programs cliapp makes it easier to write typical Unix command line programs, by taking care of the common tasks they need to do, such as |