Browse Source

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
changes/23/744023/1
Dmitriy Rabotyagov 2 months ago
parent
commit
ea07ed008f
3 changed files with 11 additions and 12 deletions
  1. +8
    -12
      action/config_template.py
  2. +1
    -0
      tests/files/test_comment_configs.ini.expected
  3. +2
    -0
      tests/test.yml

+ 8
- 12
action/config_template.py View File

@@ -204,19 +204,15 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
use_defaults = False

option = self.optionxform(option)
try:
index = sectdict.index('#%s' % option)
except (ValueError, IndexError):
sectdict[option] = value
else:
if use_defaults:
self._defaults = sectdict.insert(index, option, value)
if use_defaults:
try:
index = sectdict.index('#%s' % option)
except (ValueError, IndexError):
sectdict[option] = value
else:
self._sections[section] = sectdict.insert(
index,
option,
value
)
self._defaults = sectdict.insert(index, option, value)
else:
sectdict[option] = value

def _write(self, fp, section, key, item, entry):
if section:


+ 1
- 0
tests/files/test_comment_configs.ini.expected View File

@@ -33,6 +33,7 @@ test = test1,test2
testopt1 = 9000
# This is another test opt
#testop2 = over 9000
testop2 = below 9000

[TestSection]
things = stuff

+ 2
- 0
tests/test.yml View File

@@ -181,6 +181,8 @@
- test2
TestSection:
things: stuff
SubSection:
testop2: below 9000
diff_ini:
added:
DEFAULT:


Loading…
Cancel
Save