Changeset - 6b01e99bdb2b
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 6 years ago 2020-04-23 11:05:09
mads@kiilerich.com
Grafted from: 325f9879452c
inifile: make it possible for expand() to comment out settings without assigning new value

For completeness, when we already can create and update values, also make it
possible to delete. This fits nicely into the implementation. Potentiallly
"nice to have" but not used yet.

The ini file is a text file and it only really makes sense to set string
values. Intuitively, it makes sense that setting something to None means that
the old value should be commented out but no new value should be set. If we
want to set a value of "None", then specify "None" - not None.
1 file changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/inifile.py
Show inline comments
 
@@ -119,9 +119,6 @@ def expand(template, mako_variable_value
 
    #variable7 = 7.1
 
    #variable8 = 8.0
 
    <BLANKLINE>
 
    variable8 = None
 
    variable9 = None
 
    <BLANKLINE>
 
    [fourth-section]
 
    fourth = "four"
 
    fourth_extra = 4
 
@@ -180,7 +177,7 @@ def expand(template, mako_variable_value
 
                new_value = section_settings[key]
 
                if new_value == line_value:
 
                    line = line.lstrip('#')
 
                else:
 
                elif new_value is not None:
 
                    line += '\n%s = %s' % (key, new_value)
 
                section_settings.pop(key)
 
                return line
 
@@ -189,8 +186,12 @@ def expand(template, mako_variable_value
 

	
 
            # 3rd pass:
 
            # settings that haven't been consumed yet at is appended to section
 
            if section_settings:
 
                lines += '\n' + ''.join('%s = %s\n' % (key, value) for key, value in sorted(section_settings.items()))
 
            append_lines = ''.join(
 
                '%s = %s\n' % (key, value)
 
                for key, value in sorted(section_settings.items())
 
                if value is not None)
 
            if append_lines:
 
                lines += '\n' + append_lines
 

	
 
        return sectionname + '\n' + re.sub('[ \t]+\n', '\n', lines)
 

	
0 comments (0 inline, 0 general)