Remove old config value style

This commit is contained in:
Markus Unterwaditzer 2015-01-01 23:28:54 +01:00
parent 95e81f5383
commit 6f95870a48
3 changed files with 38 additions and 61 deletions

View file

@ -16,6 +16,8 @@ Version 0.4.1
- All ``create`` arguments from all storages are gone. Vdirsyncer now asks if - All ``create`` arguments from all storages are gone. Vdirsyncer now asks if
it should try to create collections. it should try to create collections.
- The old config values ``True``, ``False``, ``on``, ``off`` and ``None`` are
now invalid.
Version 0.4.0 Version 0.4.0
============= =============

View file

@ -55,7 +55,7 @@ def test_load_config(monkeypatch):
type = filesystem type = filesystem
path = /tmp/contacts/ path = /tmp/contacts/
fileext = .vcf fileext = .vcf
yesno = off yesno = false
number = 42 number = 42
[storage bob_b] [storage bob_b]
@ -489,45 +489,31 @@ def test_create_collections(tmpdir, runner):
set('abc') set('abc')
def test_parse_config_value(): def test_parse_config_value(capsys):
x = cli.utils.parse_config_value invalid = object()
with pytest.raises(ValueError):
x('123 # comment!')
assert x('"123 # comment!"') == '123 # comment!' def x(s):
assert x('True') is True try:
assert x('False') is False rv = cli.utils.parse_config_value(s)
assert x('Yes') is True except ValueError:
assert x('3.14') == 3.14 return invalid
assert x('') == '' else:
assert x('""') == '' warnings = capsys.readouterr()[1]
return rv, len(warnings.splitlines())
assert x('123 # comment!') is invalid
def test_parse_options(): assert x('True') == ('True', 1)
o = { assert x('False') == ('False', 1)
'foo': 'yes', assert x('Yes') == ('Yes', 1)
'hah': 'true', assert x('None') == ('None', 1)
'bar': '', assert x('"True"') == ('True', 0)
'baz': 'whatever', assert x('"False"') == ('False', 0)
'bam': '123',
'asd': 'off'
}
a = dict(cli.utils.parse_options(o.items())) assert x('"123 # comment!"') == ('123 # comment!', 0)
assert x('true') == (True, 0)
expected = { assert x('false') == (False, 0)
'foo': True, assert x('null') == (None, 0)
'hah': True, assert x('3.14') == (3.14, 0)
'bar': '', assert x('') == ('', 0)
'baz': 'whatever', assert x('""') == ('', 0)
'bam': 123,
'asd': False
}
assert a == expected
for key in a:
# Yes, we want a very strong typecheck here, because we actually have
# to differentiate between bool and int, and in Python 2, bool is a
# subclass of int.
assert a[key].__class__ is expected[key].__class__

View file

@ -471,28 +471,17 @@ def parse_config_value(value):
try: try:
return json.loads(value) return json.loads(value)
except ValueError: except ValueError:
rv = value pass
if value.lower() in ('on', 'true', 'yes'): for wrong, right in [
cli_logger.warning( (('on', 'yes'), 'true'),
'{} is deprecated for the config, please use true.\n' (('off', 'no'), 'false'),
'The old form will be removed in 0.4.0.' (('none',), 'null')
.format(value) ]:
) if value.lower() in wrong + (right,):
return True cli_logger.warning('You probably meant {} instead of "{}", which '
if value.lower() in ('off', 'false', 'no'): 'will now be interpreted as a literal string.'
cli_logger.warning( .format(right, value))
'{} is deprecated for the config, please use false.\n'
'The old form will be removed in 0.4.0.'
.format(value)
)
return False
if value.lower() == 'none':
cli_logger.warning(
'None is deprecated for the config, please use null.\n'
'The old form will be removed in 0.4.0.'
)
return None
if '#' in value: if '#' in value:
raise ValueError('Invalid value:{}\n' raise ValueError('Invalid value:{}\n'
@ -508,7 +497,7 @@ def parse_config_value(value):
# # my comment # # my comment
raise ValueError('No multiline-values allowed:\n{}'.format(value)) raise ValueError('No multiline-values allowed:\n{}'.format(value))
return rv return value
def parse_options(items, section=None): def parse_options(items, section=None):