diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index c56c078..fe75b1d 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -126,16 +126,15 @@ def sync(ctx, pairs, force_delete, max_workers): ''' from .tasks import prepare_pair, sync_collection from .utils import parse_pairs_args, WorkerQueue - general, all_pairs, all_storages = ctx.config + config = ctx.config wq = WorkerQueue(max_workers) with wq.join(): - for pair_name, collections in parse_pairs_args(pairs, all_pairs): + for pair_name, collections in parse_pairs_args(pairs, config.pairs): wq.put(functools.partial(prepare_pair, pair_name=pair_name, collections=collections, - general=general, all_pairs=all_pairs, - all_storages=all_storages, + config=config, force_delete=force_delete, callback=sync_collection)) wq.spawn_worker() @@ -154,16 +153,14 @@ def metasync(ctx, pairs, max_workers): ''' from .tasks import prepare_pair, metasync_collection from .utils import parse_pairs_args, WorkerQueue - general, all_pairs, all_storages = ctx.config + config = ctx.config wq = WorkerQueue(max_workers) with wq.join(): - for pair_name, collections in parse_pairs_args(pairs, all_pairs): + for pair_name, collections in parse_pairs_args(pairs, config.pairs): wq.put(functools.partial(prepare_pair, pair_name=pair_name, - collections=collections, - general=general, all_pairs=all_pairs, - all_storages=all_storages, + collections=collections, config=config, callback=metasync_collection)) wq.spawn_worker() @@ -179,23 +176,28 @@ def discover(ctx, pairs, max_workers): ''' from .tasks import discover_collections from .utils import WorkerQueue - general, all_pairs, all_storages = ctx.config + config = ctx.config wq = WorkerQueue(max_workers) with wq.join(): - for pair in (pairs or all_pairs): + for pair in (pairs or config.pairs): try: - name_a, name_b, pair_options = all_pairs[pair] + name_a, name_b, pair_options = config.pairs[pair] except KeyError: raise CliError('Pair not found: {}\n' 'These are the pairs found: {}' - .format(pair, list(all_pairs))) + .format(pair, list(config.pairs))) wq.put(functools.partial( - discover_collections, status_path=general['status_path'], - name_a=name_a, name_b=name_b, pair_name=pair, - config_a=all_storages[name_a], config_b=all_storages[name_b], - pair_options=pair_options, skip_cache=True + 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], + pair_options=pair_options, + skip_cache=True, )) wq.spawn_worker() @@ -217,13 +219,12 @@ def repair(ctx, collection): collection of the `calendars_local` storage. ''' from .tasks import repair_collection - general, all_pairs, all_storages = ctx.config cli_logger.warning('This operation will take a very long time.') cli_logger.warning('It\'s recommended to turn off other client\'s ' 'synchronization features.') click.confirm('Do you want to continue?', abort=True) - repair_collection(general, all_pairs, all_storages, collection) + repair_collection(ctx.config, collection) # Not sure if useful. I originally wanted it because: # * my password manager has a timeout for caching the master password diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index 0b653f0..970a596 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -79,7 +79,7 @@ def load_config(): raise CliError('Error during reading config {}: {}' .format(fname, e)) - return general, pairs, storages + return Config(general, pairs, storages) def read_config(f): @@ -175,3 +175,10 @@ def parse_options(items, section=None): except ValueError as e: raise ValueError('Section "{}", option "{}": {}' .format(section, key, e)) + + +class Config(object): + def __init__(self, general, pairs, storages): + self.general = general + self.pairs = pairs + self.storages = storages diff --git a/vdirsyncer/cli/tasks.py b/vdirsyncer/cli/tasks.py index 6b73294..ee70694 100644 --- a/vdirsyncer/cli/tasks.py +++ b/vdirsyncer/cli/tasks.py @@ -10,19 +10,18 @@ from .utils import CliError, JobFailed, cli_logger, collections_for_pair, \ from ..sync import sync -def prepare_pair(wq, pair_name, collections, general, all_pairs, all_storages, - callback, **kwargs): - a_name, b_name, pair_options = all_pairs[pair_name] +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 = all_storages[a_name], all_storages[b_name] + 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(all_storages))) + .format(pair_name, str(e), list(config.storages))) all_collections = dict(collections_for_pair( - general['status_path'], a_name, b_name, pair_name, + config.general['status_path'], a_name, b_name, pair_name, config_a, config_b, pair_options )) @@ -39,7 +38,7 @@ def prepare_pair(wq, pair_name, collections, general, all_pairs, all_storages, wq.put(functools.partial( callback, pair_name=pair_name, collection=collection, config_a=config_a, config_b=config_b, pair_options=pair_options, - general=general, **kwargs + general=config.general, **kwargs )) for i in range(new_workers): @@ -81,14 +80,14 @@ def discover_collections(wq, pair_name, **kwargs): .format(pair_name, json.dumps(collections))) -def repair_collection(general, all_pairs, all_storages, collection): +def repair_collection(config, collection): from ..repair import repair_storage storage_name, collection = collection, None if '/' in storage_name: storage_name, collection = storage_name.split('/') - config = all_storages[storage_name] + config = config.storages[storage_name] storage_type = config['type'] if collection is not None: diff --git a/vdirsyncer/utils/password.py b/vdirsyncer/utils/password.py index a9f5827..25db8ed 100644 --- a/vdirsyncer/utils/password.py +++ b/vdirsyncer/utils/password.py @@ -125,8 +125,7 @@ def _password_from_command(username, host): return None try: - general, _, _ = ctx.config - command = general['password_command'].split() + command = ctx.config.general['password_command'].split() except KeyError: return None