Sort entries in config file, so they don't jump around every time config is saved for easier troubleshooting

This commit is contained in:
Stephen Boddy 2015-08-13 22:16:35 +02:00
parent 8c8248234c
commit 4d662af20d
1 changed files with 12 additions and 0 deletions

View File

@ -2031,6 +2031,18 @@ class ConfigObj(Section):
out.append(line) out.append(line)
indent_string = self.indent_type * section.depth indent_string = self.indent_type * section.depth
# Do a little sorting for convenience
section.scalars = sorted(section.scalars)
section.sections = sorted(section.sections)
if 'default' in section.scalars:
# pop it and move to front
section.scalars.remove('default')
section.scalars.insert(0, 'default')
if 'default' in section.sections:
section.sections.remove('default')
section.sections.insert(0, 'default')
for entry in (section.scalars + section.sections): for entry in (section.scalars + section.sections):
if entry in section.defaults: if entry in section.defaults:
# don't write out default values # don't write out default values