mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Factor out deprecated config parsing
This commit is contained in:
parent
b3964ee8bb
commit
6b199474a6
2 changed files with 20 additions and 13 deletions
|
|
@ -76,14 +76,14 @@ def test_parse_pairs_args():
|
||||||
'one': ('two', 'three', {'collections': 'a,b,c'}, {}),
|
'one': ('two', 'three', {'collections': 'a,b,c'}, {}),
|
||||||
'eins': ('zwei', 'drei', {'ha': True}, {})
|
'eins': ('zwei', 'drei', {'ha': True}, {})
|
||||||
}
|
}
|
||||||
assert list(
|
assert sorted(
|
||||||
cli.parse_pairs_args(['foo/foocoll', 'one', 'eins'], pairs)
|
cli.parse_pairs_args(['foo/foocoll', 'one', 'eins'], pairs)
|
||||||
) == [
|
) == [
|
||||||
|
('eins', None),
|
||||||
('foo', 'foocoll'),
|
('foo', 'foocoll'),
|
||||||
('one', 'a'),
|
('one', 'a'),
|
||||||
('one', 'b'),
|
('one', 'b'),
|
||||||
('one', 'c'),
|
('one', 'c')
|
||||||
('eins', None)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,19 @@ def validate_section_name(name, section_type):
|
||||||
SECTION_NAME_CHARS))
|
SECTION_NAME_CHARS))
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_old_config_list_value(d, key):
|
||||||
|
value = d.get(key, [])
|
||||||
|
if isinstance(value, str):
|
||||||
|
# XXX: Deprecation
|
||||||
|
old_form = value
|
||||||
|
value = list(filter(bool, (x.strip() for x in value.split(','))))
|
||||||
|
cli_logger.warning(
|
||||||
|
'{!r} is deprecated, please use:\n{} = {}\n'
|
||||||
|
'The old form will be removed in 0.4.0.'
|
||||||
|
.format(old_form, key, json.dumps(value)))
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def get_status_name(pair, collection):
|
def get_status_name(pair, collection):
|
||||||
if collection is None:
|
if collection is None:
|
||||||
return pair
|
return pair
|
||||||
|
|
@ -231,16 +244,10 @@ def parse_pairs_args(pairs_args, all_pairs):
|
||||||
.format(pair, list(all_pairs)))
|
.format(pair, list(all_pairs)))
|
||||||
|
|
||||||
if collection is None:
|
if collection is None:
|
||||||
collections = pair_options.get('collections', [None])
|
collections = set(
|
||||||
if isinstance(collections, str):
|
_parse_old_config_list_value(pair_options, 'collections')
|
||||||
# XXX: Deprecation
|
or [None]
|
||||||
orig_collections = collections
|
)
|
||||||
collections = [x.strip() or None
|
|
||||||
for x in collections.split(',')]
|
|
||||||
cli_logger.warning(
|
|
||||||
'{!r} is deprecated, please use:\ncollections = {}\n'
|
|
||||||
'The old form will be removed in 0.4.0.'
|
|
||||||
.format(orig_collections, json.dumps(collections)))
|
|
||||||
else:
|
else:
|
||||||
collections = [collection]
|
collections = [collection]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue