Add dump_userconfig

This commit is contained in:
Florian Bruhin 2017-06-16 14:37:56 +02:00
parent b5eac744b5
commit 785de9fb99
2 changed files with 12 additions and 16 deletions

View File

@ -720,22 +720,6 @@ class ConfigManager(QObject):
with qtutils.savefile_open(configfile) as f:
f.write(str(self))
def dump_userconfig(self):
"""Get the part of the config which was changed by the user.
Return:
The changed config part as string.
"""
lines = []
for sectname, sect in self.sections.items():
changed = sect.dump_userconfig()
if changed:
lines.append('[{}]'.format(sectname))
lines += ['{} = {}'.format(k, v) for k, v in changed]
if not lines:
lines = ['<Default configuration>']
return '\n'.join(lines)
def optionxform(self, val):
"""Implemented to be compatible with ConfigParser interpolation."""
return val

View File

@ -258,6 +258,18 @@ class NewConfigManager(QObject):
self._values[name] = opt.typ.from_str(value)
self.changed.emit(name)
def dump_userconfig(self):
"""Get the part of the config which was changed by the user.
Return:
The changed config part as string.
"""
lines = ['{} = {}'.format(optname, value)
for optname, value in self._values.items()]
if not lines:
lines = ['<Default configuration>']
return '\n'.join(lines)
class ConfigContainer: