Remove unnecessary params, fix tests

This commit is contained in:
Markus Unterwaditzer 2015-08-20 15:49:36 +02:00
parent 0041934318
commit d59376e231
5 changed files with 23 additions and 22 deletions

View file

@ -16,6 +16,7 @@ import requests
from vdirsyncer import utils
from vdirsyncer.cli import pass_context
from vdirsyncer.cli.config import Config
# These modules might be uninitialized and unavailable if not explicitly
# imported
@ -119,7 +120,7 @@ def test_get_password_from_command(tmpdir):
@click.command()
@pass_context
def fake_app(ctx):
ctx.config = {'password_command': filepath}, {}, {}
ctx.config = Config({'password_command': filepath}, {}, {})
_password = utils.password.get_password(username, resource)
assert _password == password

View file

@ -191,11 +191,9 @@ def discover(ctx, pairs, max_workers):
wq.put(functools.partial(
discover_collections,
status_path=config.general['status_path'],
name_a=name_a,
name_b=name_b,
pair_name=pair,
config_a=config.storages[name_a],
config_b=config.storages[name_b],
config_a=config.get_storage_args(name_a),
config_b=config.get_storage_args(name_b),
pair_options=pair_options,
skip_cache=True,
))

View file

@ -182,3 +182,12 @@ class Config(object):
self.general = general
self.pairs = pairs
self.storages = storages
def get_storage_args(self, storage_name):
try:
return self.storages[storage_name]
except KeyError:
raise CliError(
'Storage {!r} not found. These are the configured storages: {}'
.format(storage_name, list(self.storages))
)

View file

@ -13,16 +13,12 @@ from ..sync import sync
def prepare_pair(wq, pair_name, collections, config, callback, **kwargs):
a_name, b_name, pair_options = config.pairs[pair_name]
try:
config_a, config_b = config.storages[a_name], config.storages[b_name]
except KeyError as e:
raise CliError('Pair {}: Storage {} not found. These are the '
'configured storages: {}'
.format(pair_name, str(e), list(config.storages)))
config_a = config.get_storage_args(a_name)
config_b = config.get_storage_args(b_name)
all_collections = dict(collections_for_pair(
config.general['status_path'], a_name, b_name, pair_name,
config_a, config_b, pair_options
status_path=config.general['status_path'], pair_name=pair_name,
config_a=config_a, config_b=config_b, pair_options=pair_options
))
# spawn one worker less because we can reuse the current one
@ -87,7 +83,7 @@ def repair_collection(config, collection):
if '/' in storage_name:
storage_name, collection = storage_name.split('/')
config = config.storages[storage_name]
config = config.get_storage_args(storage_name)
storage_type = config['type']
if collection is not None:

View file

@ -139,14 +139,12 @@ def _get_collections_cache_key(pair_options, config_a, config_b):
return m.hexdigest()
def collections_for_pair(status_path, name_a, name_b, pair_name, config_a,
def collections_for_pair(status_path, pair_name, config_a,
config_b, pair_options, skip_cache=False):
'''Determine all configured collections for a given pair. Takes care of
shortcut expansion and result caching.
:param status_path: The path to the status directory.
:param name_a: The config name of storage A.
:param name_b: The config name of storage B.
:param pair_name: The config name of the pair.
:param config_a: The configuration for storage A.
:param config_b: The configuration for storage B.
@ -172,9 +170,8 @@ def collections_for_pair(status_path, name_a, name_b, pair_name, config_a,
# We have to use a list here because the special None/null value would get
# mangled to string (because JSON objects always have string keys).
rv = list(_collections_for_pair_impl(status_path, name_a, name_b,
pair_name, config_a, config_b,
pair_options))
rv = list(_collections_for_pair_impl(status_path, pair_name, config_a,
config_b, pair_options))
save_status(status_path, pair_name, data_type='collections',
data={
@ -250,8 +247,8 @@ def _handle_collection_not_found(config, collection, e=None):
storage=storage_name))
def _collections_for_pair_impl(status_path, name_a, name_b, pair_name,
config_a, config_b, pair_options):
def _collections_for_pair_impl(status_path, pair_name, config_a, config_b,
pair_options):
shortcuts = set(pair_options.get('collections', ()))
if not shortcuts: