mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Remove unnecessary params, fix tests
This commit is contained in:
parent
0041934318
commit
d59376e231
5 changed files with 23 additions and 22 deletions
|
|
@ -16,6 +16,7 @@ import requests
|
||||||
|
|
||||||
from vdirsyncer import utils
|
from vdirsyncer import utils
|
||||||
from vdirsyncer.cli import pass_context
|
from vdirsyncer.cli import pass_context
|
||||||
|
from vdirsyncer.cli.config import Config
|
||||||
|
|
||||||
# These modules might be uninitialized and unavailable if not explicitly
|
# These modules might be uninitialized and unavailable if not explicitly
|
||||||
# imported
|
# imported
|
||||||
|
|
@ -119,7 +120,7 @@ def test_get_password_from_command(tmpdir):
|
||||||
@click.command()
|
@click.command()
|
||||||
@pass_context
|
@pass_context
|
||||||
def fake_app(ctx):
|
def fake_app(ctx):
|
||||||
ctx.config = {'password_command': filepath}, {}, {}
|
ctx.config = Config({'password_command': filepath}, {}, {})
|
||||||
_password = utils.password.get_password(username, resource)
|
_password = utils.password.get_password(username, resource)
|
||||||
assert _password == password
|
assert _password == password
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,11 +191,9 @@ def discover(ctx, pairs, max_workers):
|
||||||
wq.put(functools.partial(
|
wq.put(functools.partial(
|
||||||
discover_collections,
|
discover_collections,
|
||||||
status_path=config.general['status_path'],
|
status_path=config.general['status_path'],
|
||||||
name_a=name_a,
|
|
||||||
name_b=name_b,
|
|
||||||
pair_name=pair,
|
pair_name=pair,
|
||||||
config_a=config.storages[name_a],
|
config_a=config.get_storage_args(name_a),
|
||||||
config_b=config.storages[name_b],
|
config_b=config.get_storage_args(name_b),
|
||||||
pair_options=pair_options,
|
pair_options=pair_options,
|
||||||
skip_cache=True,
|
skip_cache=True,
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -182,3 +182,12 @@ class Config(object):
|
||||||
self.general = general
|
self.general = general
|
||||||
self.pairs = pairs
|
self.pairs = pairs
|
||||||
self.storages = storages
|
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))
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,12 @@ from ..sync import sync
|
||||||
def prepare_pair(wq, pair_name, collections, config, callback, **kwargs):
|
def prepare_pair(wq, pair_name, collections, config, callback, **kwargs):
|
||||||
a_name, b_name, pair_options = config.pairs[pair_name]
|
a_name, b_name, pair_options = config.pairs[pair_name]
|
||||||
|
|
||||||
try:
|
config_a = config.get_storage_args(a_name)
|
||||||
config_a, config_b = config.storages[a_name], config.storages[b_name]
|
config_b = config.get_storage_args(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)))
|
|
||||||
|
|
||||||
all_collections = dict(collections_for_pair(
|
all_collections = dict(collections_for_pair(
|
||||||
config.general['status_path'], a_name, b_name, pair_name,
|
status_path=config.general['status_path'], pair_name=pair_name,
|
||||||
config_a, config_b, pair_options
|
config_a=config_a, config_b=config_b, pair_options=pair_options
|
||||||
))
|
))
|
||||||
|
|
||||||
# spawn one worker less because we can reuse the current one
|
# spawn one worker less because we can reuse the current one
|
||||||
|
|
@ -87,7 +83,7 @@ def repair_collection(config, collection):
|
||||||
if '/' in storage_name:
|
if '/' in storage_name:
|
||||||
storage_name, collection = storage_name.split('/')
|
storage_name, collection = storage_name.split('/')
|
||||||
|
|
||||||
config = config.storages[storage_name]
|
config = config.get_storage_args(storage_name)
|
||||||
storage_type = config['type']
|
storage_type = config['type']
|
||||||
|
|
||||||
if collection is not None:
|
if collection is not None:
|
||||||
|
|
|
||||||
|
|
@ -139,14 +139,12 @@ def _get_collections_cache_key(pair_options, config_a, config_b):
|
||||||
return m.hexdigest()
|
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):
|
config_b, pair_options, skip_cache=False):
|
||||||
'''Determine all configured collections for a given pair. Takes care of
|
'''Determine all configured collections for a given pair. Takes care of
|
||||||
shortcut expansion and result caching.
|
shortcut expansion and result caching.
|
||||||
|
|
||||||
:param status_path: The path to the status directory.
|
: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 pair_name: The config name of the pair.
|
||||||
:param config_a: The configuration for storage A.
|
:param config_a: The configuration for storage A.
|
||||||
:param config_b: The configuration for storage B.
|
: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
|
# 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).
|
# mangled to string (because JSON objects always have string keys).
|
||||||
rv = list(_collections_for_pair_impl(status_path, name_a, name_b,
|
rv = list(_collections_for_pair_impl(status_path, pair_name, config_a,
|
||||||
pair_name, config_a, config_b,
|
config_b, pair_options))
|
||||||
pair_options))
|
|
||||||
|
|
||||||
save_status(status_path, pair_name, data_type='collections',
|
save_status(status_path, pair_name, data_type='collections',
|
||||||
data={
|
data={
|
||||||
|
|
@ -250,8 +247,8 @@ def _handle_collection_not_found(config, collection, e=None):
|
||||||
storage=storage_name))
|
storage=storage_name))
|
||||||
|
|
||||||
|
|
||||||
def _collections_for_pair_impl(status_path, name_a, name_b, pair_name,
|
def _collections_for_pair_impl(status_path, pair_name, config_a, config_b,
|
||||||
config_a, config_b, pair_options):
|
pair_options):
|
||||||
|
|
||||||
shortcuts = set(pair_options.get('collections', ()))
|
shortcuts = set(pair_options.get('collections', ()))
|
||||||
if not shortcuts:
|
if not shortcuts:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue