Fix section overrides when commented option persist
In cases, when key already exist, but commented out without space (ie "#key) and is not in default section, it's not updated with sectdict.insert statement. That is possible happens because self._sections keys are protected and can't be overwritten (at least new assignment makes no difference) Change-Id: Ie0c588a2d559bd38c68b3d018e547a036d83214c Closes-Bug: #1889547
This commit is contained in:
parent
4ed672e399
commit
ea07ed008f
|
@ -204,19 +204,15 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
|
||||||
use_defaults = False
|
use_defaults = False
|
||||||
|
|
||||||
option = self.optionxform(option)
|
option = self.optionxform(option)
|
||||||
try:
|
if use_defaults:
|
||||||
index = sectdict.index('#%s' % option)
|
try:
|
||||||
except (ValueError, IndexError):
|
index = sectdict.index('#%s' % option)
|
||||||
sectdict[option] = value
|
except (ValueError, IndexError):
|
||||||
else:
|
sectdict[option] = value
|
||||||
if use_defaults:
|
|
||||||
self._defaults = sectdict.insert(index, option, value)
|
|
||||||
else:
|
else:
|
||||||
self._sections[section] = sectdict.insert(
|
self._defaults = sectdict.insert(index, option, value)
|
||||||
index,
|
else:
|
||||||
option,
|
sectdict[option] = value
|
||||||
value
|
|
||||||
)
|
|
||||||
|
|
||||||
def _write(self, fp, section, key, item, entry):
|
def _write(self, fp, section, key, item, entry):
|
||||||
if section:
|
if section:
|
||||||
|
|
|
@ -33,6 +33,7 @@ test = test1,test2
|
||||||
testopt1 = 9000
|
testopt1 = 9000
|
||||||
# This is another test opt
|
# This is another test opt
|
||||||
#testop2 = over 9000
|
#testop2 = over 9000
|
||||||
|
testop2 = below 9000
|
||||||
|
|
||||||
[TestSection]
|
[TestSection]
|
||||||
things = stuff
|
things = stuff
|
||||||
|
|
|
@ -181,6 +181,8 @@
|
||||||
- test2
|
- test2
|
||||||
TestSection:
|
TestSection:
|
||||||
things: stuff
|
things: stuff
|
||||||
|
SubSection:
|
||||||
|
testop2: below 9000
|
||||||
diff_ini:
|
diff_ini:
|
||||||
added:
|
added:
|
||||||
DEFAULT:
|
DEFAULT:
|
||||||
|
|
Loading…
Reference in New Issue