Changeset - 06ae370ffaa3
[Not reviewed]
default
0 1 0
Mads Kiilerich - 8 years ago 2018-03-11 15:24:47
mads@kiilerich.com
Grafted from: 856ac96f3f9a
ini: only keep default value as comment if the custom value actually is different
1 file changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/inifile.py
Show inline comments
 
@@ -103,26 +103,28 @@ def expand(template, mako_variable_value
 

	
 
    def process_section(m):
 
        """process a ini section, replacing values as necessary"""
 
        sectionname, lines = m.groups()
 
        if sectionname in settings:
 
            section_settings = settings.pop(sectionname)
 

	
 
            def process_line(m):
 
                """process a section line and update value if necessary"""
 
                key, value = m.groups()
 
                line = m.group(0)
 
                if key in section_settings:
 
                    # keep old entry as example - comments might refer to it
 
                    line = '#%s\n%s = %s' % (line, key, section_settings.pop(key))
 
                    new_line = '%s = %s' % (key, section_settings.pop(key))
 
                    if new_line != line:
 
                        # keep old entry as example - comments might refer to it
 
                        line = '#%s\n%s' % (line, new_line)
 
                return line.rstrip()
 

	
 
            # process lines that not are comments or empty and look like name=value
 
            lines = re.sub(r'^([^#\n\s]*)[ \t]*=[ \t]*(.*)$', process_line, lines, flags=re.MULTILINE)
 
            # add unused section settings
 
            if section_settings:
 
                lines += '\n' + ''.join('%s = %s\n' % (key, value) for key, value in sorted(section_settings.items()))
 

	
 
        return sectionname + '\n' + lines
 

	
 
    # process sections until comments before next section or end
 
    ini_lines = re.sub(r'''^
0 comments (0 inline, 0 general)