Skip to content

Commit

Permalink
Make status_path relative to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Jan 12, 2015
1 parent 5fa05bc commit ce2cea1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
3 changes: 2 additions & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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 == {
Expand Down Expand Up @@ -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()

Expand Down
15 changes: 1 addition & 14 deletions vdirsyncer/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
'''

import functools
import os
import sys

from .tasks import discover_collections, sync_pair
from .utils import CliError, WorkerQueue, cli_logger, handle_cli_error, \
load_config, parse_pairs_args
from .. import __version__, log
from ..doubleclick import click
from ..utils import expand_path


def catch_errors(f):
Expand Down Expand Up @@ -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

Expand Down
22 changes: 20 additions & 2 deletions vdirsyncer/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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


Expand Down

0 comments on commit ce2cea1

Please sign in to comment.