Add some comments to generated config.py

This commit is contained in:
Florian Bruhin 2017-10-04 11:43:14 +02:00
parent 7fc5e42cca
commit 6fa001481d

View File

@ -248,11 +248,31 @@ class ConfigAPI:
def write_config_py(filename, options, bindings):
"""Write a config.py file from given values."""
with open(filename, 'w', encoding='utf-8') as f:
f.write("# Autogenerated config.py - please remove lines you don't "
"customize!\n")
f.write("# Documentation:\n")
f.write("# qute://help/configuring.html\n")
f.write("# qute://help/settings.html\n\n")
for opt, value in options:
if opt.name in ['bindings.commands', 'bindings.default']:
continue
for line in textwrap.wrap(opt.description):
f.write('# {}\n'.format(line))
f.write('# Type: {}\n'.format(opt.typ.get_name()))
valid_values = opt.typ.get_valid_values()
if valid_values is not None:
f.write("# Valid values:\n")
for val in valid_values:
try:
desc = valid_values.descriptions[val]
f.write("# - {}: {}".format(val, desc) + "\n")
except KeyError:
f.write("# - {}".format(val) + "\n")
f.write('c.{} = {!r}\n\n'.format(opt.name, value))
normal_bindings = bindings.pop('normal', {})