mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-06-28 05:19:33 +00:00
Don't fail when discovery fails
This commit is contained in:
parent
d454093365
commit
dd465eb909
2 changed files with 30 additions and 7 deletions
|
|
@ -25,6 +25,20 @@ missing = object()
|
|||
('b3', (missing,
|
||||
{'type': 'fooboo', 'custom_arg': 'b3', 'collection': 'b3'}))
|
||||
]),
|
||||
(['from a', 'from b'], [
|
||||
('c1', ({'type': 'fooboo', 'custom_arg': 'a1', 'collection': 'c1'},
|
||||
{'type': 'fooboo', 'custom_arg': 'b1', 'collection': 'c1'})),
|
||||
('c2', ({'type': 'fooboo', 'custom_arg': 'a2', 'collection': 'c2'},
|
||||
{'type': 'fooboo', 'custom_arg': 'b2', 'collection': 'c2'})),
|
||||
('a3', ({'type': 'fooboo', 'custom_arg': 'a3', 'collection': 'a3'},
|
||||
missing)),
|
||||
('b3', (missing,
|
||||
{'type': 'fooboo', 'custom_arg': 'b3', 'collection': 'b3'}))
|
||||
]),
|
||||
([['c12', 'c1', 'c2']], [
|
||||
('c12', ({'type': 'fooboo', 'custom_arg': 'a1', 'collection': 'c1'},
|
||||
{'type': 'fooboo', 'custom_arg': 'b2', 'collection': 'c2'})),
|
||||
]),
|
||||
(None, [
|
||||
(None, ({'type': 'fooboo', 'storage_side': 'a', 'collection': None},
|
||||
{'type': 'fooboo', 'storage_side': 'b', 'collection': None}))
|
||||
|
|
@ -59,9 +73,9 @@ def test_expand_collections(shortcuts, expected):
|
|||
'b3': {'type': 'fooboo', 'custom_arg': 'b3', 'collection': 'b3'}
|
||||
}
|
||||
|
||||
assert list(expand_collections(
|
||||
assert sorted(expand_collections(
|
||||
shortcuts,
|
||||
config_a, config_b,
|
||||
get_discovered_a, get_discovered_b,
|
||||
lambda config, collection: missing
|
||||
)) == expected
|
||||
)) == sorted(expected)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from .utils import handle_collection_not_found, handle_storage_init_error, \
|
||||
load_status, save_status, storage_class_from_config, \
|
||||
|
|
@ -65,9 +66,9 @@ def collections_for_pair(status_path, pair, from_cache=True,
|
|||
|
||||
if list_collections:
|
||||
_print_collections(pair.config_a['instance_name'],
|
||||
a_discovered.get_self())
|
||||
a_discovered.get_self)
|
||||
_print_collections(pair.config_b['instance_name'],
|
||||
b_discovered.get_self())
|
||||
b_discovered.get_self)
|
||||
|
||||
# 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).
|
||||
|
|
@ -94,7 +95,7 @@ def collections_for_pair(status_path, pair, from_cache=True,
|
|||
|
||||
|
||||
def _sanity_check_collections(collections):
|
||||
for collection, (a_args, b_args) in collections:
|
||||
for _, (a_args, b_args) in collections:
|
||||
storage_instance_from_config(a_args)
|
||||
storage_instance_from_config(b_args)
|
||||
|
||||
|
|
@ -169,7 +170,8 @@ def expand_collections(shortcuts, config_a, config_b, get_a_discovered,
|
|||
else:
|
||||
collection_a = collection_b = collection
|
||||
|
||||
assert collection not in handled_collections
|
||||
if collection in handled_collections:
|
||||
continue
|
||||
handled_collections.add(collection)
|
||||
|
||||
a_args = _collection_from_discovered(
|
||||
|
|
@ -197,7 +199,14 @@ def _collection_from_discovered(get_discovered, collection, config,
|
|||
return _handle_collection_not_found(config, collection)
|
||||
|
||||
|
||||
def _print_collections(instance_name, discovered):
|
||||
def _print_collections(instance_name, get_discovered):
|
||||
try:
|
||||
discovered = get_discovered()
|
||||
except Exception:
|
||||
import traceback
|
||||
logger.debug(''.join(traceback.format_tb(sys.exc_info()[2])))
|
||||
logger.warning('Failed to discover collections for {}, use `-vdebug` '
|
||||
'to see the full traceback.'.format(instance_name))
|
||||
logger.info('{}:'.format(instance_name))
|
||||
for args in discovered.values():
|
||||
collection = args['collection']
|
||||
|
|
|
|||
Loading…
Reference in a new issue