diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e62b0ce6d..a86d2f2c6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,6 +16,8 @@ Version 0.4.2 - Vdirsyncer now respects redirects when uploading and updating items. This might fix issues with Zimbra. +- Relative ``status_path`` values are now interpreted as relative to the + configuration file's directory. Version 0.4.1 ============= diff --git a/docs/config.rst b/docs/config.rst index 6e79ce43b..6073fe0a2 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -32,7 +32,8 @@ General Section - ``status_path``: A directory where vdirsyncer will store metadata for the next sync. The data is needed to determine whether a new item means it has - been added on one side or deleted on the other. + been added on one side or deleted on the other. Relative paths will be + interpreted as relative to the configuration file's directory. - ``password_command`` specifies a command to query for server passwords. The command will be called with the username as the first argument, and the diff --git a/tests/test_cli.py b/tests/test_cli.py index 12cc7f5fd..be405105f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -40,7 +40,7 @@ def runner(tmpdir, monkeypatch): return _CustomRunner(tmpdir) -def test_load_config(monkeypatch): +def test_read_config(monkeypatch): f = io.StringIO(dedent(u''' [general] status_path = /tmp/status/ @@ -67,7 +67,7 @@ def test_load_config(monkeypatch): errors = [] monkeypatch.setattr('vdirsyncer.cli.cli_logger.error', errors.append) - general, pairs, storages = cli.load_config(f) + general, pairs, storages = cli.utils.read_config(f) assert general == {'status_path': '/tmp/status/'} assert pairs == {'bob': ('bob_a', 'bob_b', {'bam': True, 'foo': 'bar'})} assert storages == { @@ -234,7 +234,7 @@ def test_invalid_storage_name(): ''')) with pytest.raises(cli.CliError) as excinfo: - cli.load_config(f) + cli.utils.read_config(f) assert 'invalid characters' in str(excinfo.value).lower() diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 318dec709..affb6367b 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -8,7 +8,6 @@ ''' import functools -import os import sys from .tasks import discover_collections, sync_pair @@ -16,7 +15,6 @@ load_config, parse_pairs_args from .. import __version__, log from ..doubleclick import click -from ..utils import expand_path def catch_errors(f): @@ -58,18 +56,7 @@ def app(ctx, verbosity): ctx.obj = {} 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: - with open(fname) as f: - ctx.obj['config'] = load_config(f) - except Exception as e: - raise CliError('Error during reading config {}: {}' - .format(fname, e)) + ctx.obj['config'] = load_config() main = app diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index 61db4874b..0516487cb 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -250,7 +250,26 @@ def _validate_pair_section(pair_config): raise e -def load_config(f): +def load_config(): + 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: + with open(fname) as f: + general, pairs, storages = read_config(f) + _validate_general_section(general) + general['status_path'] = os.path.join(fname, general['status_path']) + except Exception as e: + raise CliError('Error during reading config {}: {}' + .format(fname, e)) + + return general, pairs, storages + + +def read_config(f): c = RawConfigParser() c.readfp(f) @@ -293,7 +312,6 @@ def bad_section(name, options): except ValueError as e: raise CliError('Section `{}`: {}'.format(section, str(e))) - _validate_general_section(general) return general, pairs, storages