Add command descriptions to config file generation
This commit is contained in:
parent
e4cd92a293
commit
277f4d841d
@ -57,6 +57,7 @@ class NewConfig:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = configdata.configdata()
|
self.config = configdata.configdata()
|
||||||
|
print(str(self))
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Get a section from the config."""
|
"""Get a section from the config."""
|
||||||
@ -65,21 +66,39 @@ class NewConfig:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Get the whole config as a string."""
|
"""Get the whole config as a string."""
|
||||||
# FIXME empty lines get discared
|
# FIXME empty lines get discared
|
||||||
# FIXME we should set subsequent_indent for config options later
|
normal_wrapper = textwrap.TextWrapper(
|
||||||
wrapper = textwrap.TextWrapper(
|
|
||||||
width=72, replace_whitespace=False, break_long_words=False,
|
width=72, replace_whitespace=False, break_long_words=False,
|
||||||
break_on_hyphens=False, initial_indent='# ',
|
break_on_hyphens=False, initial_indent='# ',
|
||||||
subsequent_indent='# ')
|
subsequent_indent='# ')
|
||||||
|
option_wrapper = textwrap.TextWrapper(
|
||||||
|
width=72, replace_whitespace=False, break_long_words=False,
|
||||||
|
break_on_hyphens=False, initial_indent='# ',
|
||||||
|
subsequent_indent='# ')
|
||||||
lines = []
|
lines = []
|
||||||
for par in map(wrapper.wrap, configdata.FIRST_COMMENT.splitlines()):
|
for par in map(normal_wrapper.wrap,
|
||||||
|
configdata.FIRST_COMMENT.splitlines()):
|
||||||
lines += par
|
lines += par
|
||||||
for secname, section in self.config.items():
|
for secname, section in self.config.items():
|
||||||
lines.append('\n[{}]'.format(secname))
|
lines.append('\n\n[{}]\n'.format(secname))
|
||||||
for par in map(wrapper.wrap,
|
seclines = configdata.SECTION_DESC[secname].splitlines()
|
||||||
configdata.SECTION_DESC[secname].splitlines()):
|
for secline in seclines:
|
||||||
lines += par
|
if 'http://' in secline:
|
||||||
|
lines.append('# ' + secline)
|
||||||
|
else:
|
||||||
|
lines += normal_wrapper.wrap(secline)
|
||||||
|
lines.append('')
|
||||||
for optname, option in section.items():
|
for optname, option in section.items():
|
||||||
# FIXME display option comment
|
try:
|
||||||
|
desc = self.config[secname].descriptions[optname]
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
wrapped_desc = []
|
||||||
|
for descline in desc.splitlines():
|
||||||
|
if 'http://' in descline:
|
||||||
|
wrapped_desc.append('# ' + descline)
|
||||||
|
else:
|
||||||
|
wrapped_desc += option_wrapper.wrap(descline)
|
||||||
|
lines.append('\n'.join(wrapped_desc))
|
||||||
lines.append('{} = {}'.format(optname, option))
|
lines.append('{} = {}'.format(optname, option))
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ class KeyValue:
|
|||||||
values: An OrderedDict with key as index and value as value.
|
values: An OrderedDict with key as index and value as value.
|
||||||
key: string
|
key: string
|
||||||
value: SettingValue
|
value: SettingValue
|
||||||
|
descriptions: A dict with the description strings for the keys.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -47,9 +48,11 @@ class KeyValue:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if args:
|
if args:
|
||||||
|
self.descriptions = {}
|
||||||
self.values = OrderedDict()
|
self.values = OrderedDict()
|
||||||
for (k, settingval, desc) in args:
|
for (k, settingval, desc) in args:
|
||||||
self.values[k] = settingval
|
self.values[k] = settingval
|
||||||
|
self.descriptions[k] = desc
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Get the value for key.
|
"""Get the value for key.
|
||||||
|
@ -84,12 +84,16 @@ class ValueListSection:
|
|||||||
default: An OrderedDict with the default configuration as strings.
|
default: An OrderedDict with the default configuration as strings.
|
||||||
After __init__, the strings become key/value types.
|
After __init__, the strings become key/value types.
|
||||||
types: A tuple for (keytype, valuetype)
|
types: A tuple for (keytype, valuetype)
|
||||||
|
descriptions: A dict with the description strings for the keys.
|
||||||
|
Currently a global empty dict to be compatible with
|
||||||
|
KeyValue section.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
values = None
|
values = None
|
||||||
default = None
|
default = None
|
||||||
types = None
|
types = None
|
||||||
|
descriptions = {}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Wrap types over default values. Take care when overriding this."""
|
"""Wrap types over default values. Take care when overriding this."""
|
||||||
|
Loading…
Reference in New Issue
Block a user