Merge pull request #152 from hobarrera/xdg-basedir

Support the XDG-Basedir specification
This commit is contained in:
Markus Unterwaditzer 2014-12-15 19:58:33 +01:00
commit ddd8ab675e
3 changed files with 15 additions and 4 deletions

View file

@ -21,12 +21,14 @@ Installation and usage
======================
If you already have it installed and want to quickly configure it, copy the
``example.cfg`` to ``~/.vdirsyncer/config`` and edit it.
``example.cfg`` to ``~/.vdirsyncer/config`` [1]_ and edit it.
If that method doesn't work for you or you want a deeper understanding of what
you just did, check out `the tutorial
<https://vdirsyncer.readthedocs.org/en/latest/tutorial.html>`_.
.. [1] The configuration file can also be placed in ``$XDG_CONFIG_HOME/vdirsyncer/config`` (normally ``~/.config/vdirsyncer/config``) for XDG-Basedir spec compliance.
Donations
=========

View file

@ -33,9 +33,14 @@ Configuration
- Take a look at the :doc:`problems` page if anything doesn't work like
planned.
By default, *vdirsyncer* looks for its configuration file at
``~/.vdirsyncer/config``. You can use the ``VDIRSYNCER_CONFIG`` environment
variable to change this path.
By default, *vdirsyncer* looks for its configuration file in the following
locations:
- The file pointed to by the ``VDIRSYNCER_CONFIG`` environment variable.
- ``~/.vdirsyncer/config``.
- ``$XDG_CONFIG_HOME/vdirsyncer/config``, which is normally
``~/.config/vdirsyncer/config``. This is XDG-Basedir compliant, and should
help keep your ``$HOME`` clean.
The config file should start with a :ref:`general section <general_config>`,
where the only required parameter is ``status_path``. The following is a

View file

@ -278,6 +278,10 @@ def _create_app():
if 'config' not in ctx.obj:
fname = expand_path(os.environ.get('VDIRSYNCER_CONFIG',
'~/.vdirsyncer/config'))
if not os.path.exists(fname):
xdg_config_dir = os.environ.get('XDG_CONFIG_HOME',
expand_path('~/.config/'))
fname = os.path.join(xdg_config_dir, 'vdirsyncer/config')
try:
ctx.obj['config'] = load_config(fname)
except Exception as e: