From 6b199474a6b360c241daa3583517c958bf8c4379 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Mon, 15 Dec 2014 21:12:54 +0100 Subject: [PATCH] Factor out deprecated config parsing --- tests/test_cli.py | 6 +++--- vdirsyncer/cli.py | 27 +++++++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index ca821ad..79810d4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -76,14 +76,14 @@ def test_parse_pairs_args(): 'one': ('two', 'three', {'collections': 'a,b,c'}, {}), 'eins': ('zwei', 'drei', {'ha': True}, {}) } - assert list( + assert sorted( cli.parse_pairs_args(['foo/foocoll', 'one', 'eins'], pairs) ) == [ + ('eins', None), ('foo', 'foocoll'), ('one', 'a'), ('one', 'b'), - ('one', 'c'), - ('eins', None) + ('one', 'c') ] diff --git a/vdirsyncer/cli.py b/vdirsyncer/cli.py index fed162d..2979a90 100644 --- a/vdirsyncer/cli.py +++ b/vdirsyncer/cli.py @@ -59,6 +59,19 @@ def validate_section_name(name, section_type): 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): if collection is None: return pair @@ -231,16 +244,10 @@ def parse_pairs_args(pairs_args, all_pairs): .format(pair, list(all_pairs))) if collection is None: - collections = pair_options.get('collections', [None]) - if isinstance(collections, str): - # XXX: Deprecation - 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))) + collections = set( + _parse_old_config_list_value(pair_options, 'collections') + or [None] + ) else: collections = [collection]