More config output improvments

This commit is contained in:
Florian Bruhin 2014-02-27 22:29:25 +01:00
parent c74bfdef0e
commit 22506fd6f4
2 changed files with 11 additions and 10 deletions

View File

@ -91,8 +91,6 @@ class NewConfig:
lines.append('# ' + secline)
else:
lines += wrapper.wrap(secline)
if self.config[secname].descriptions:
lines.append('#')
return lines
def _str_option_desc(self, secname, section):
@ -103,6 +101,7 @@ class NewConfig:
if not section.descriptions:
return lines
for optname, option in section.items():
lines.append('#')
if option.typ.typestr is None:
typestr = ''
else:
@ -112,19 +111,17 @@ class NewConfig:
desc = self.config[secname].descriptions[optname]
except KeyError:
continue
wrapped_desc = []
for descline in desc.splitlines():
wrapped_desc += wrapper.wrap(descline)
lines += wrapper.wrap(descline)
valid_values = option.typ.valid_values
if valid_values is not None:
if valid_values is not None and option.typ.show_valid_values:
if isinstance(valid_values[0], str):
wrapped_desc += wrapper.wrap('Valid values: {}'.format(
', '.join(valid_values)))
lines += wrapper.wrap('Valid values: {}'.format(', '.join(
valid_values)))
else:
for (val, desc) in valid_values:
wrapped_desc += wrapper.wrap(
' {}: {}'.format(val, desc))
lines.append('\n'.join(wrapped_desc))
lines += wrapper.wrap(' {}: {}'.format(val, desc))
lines += wrapper.wrap('Default: {}'.format(option.default))
return lines
def _str_items(self, section):

View File

@ -29,12 +29,14 @@ class BaseType:
string. Either a list of strings, or a list of (value,
desc) tuples.
# FIXME actually handle tuples and stuff when validating
show_valid_values; Whether to show valid values in config or not.
typestr: The name of the type to appear in the config.
"""
typestr = None
valid_values = None
show_valid_values = True
def transform(self, value):
"""Transform the setting value.
@ -83,6 +85,7 @@ class Bool(BaseType):
"""Base class for a boolean setting."""
valid_values = ['true', 'false']
show_valid_values = False
typestr = 'bool'
# Taken from configparser
@ -240,6 +243,7 @@ class AutoSearch(Bool):
"""Whether to start a search when something else than an URL is entered."""
typestr = None
valid_values = [("naive", "Use simple/naive check."),
("dns", "Use DNS requests (might be slow!)."),
("false", "Never search automatically.")]