Merge pull request #2590 from noseka1/devel

Fix ini_file module, avoid bracklets in key break idempotence
reviewable/pr18780/r1
Brian Coca 9 years ago
commit 8a2459c643

@ -99,6 +99,22 @@ import ConfigParser
import sys
import os
# ==============================================================
# match_opt
def match_opt(option, line):
option = re.escape(option)
return re.match('%s *=' % option, line) \
or re.match('# *%s *=' % option, line) \
or re.match('; *%s *=' % option, line)
# ==============================================================
# match_active_opt
def match_active_opt(option, line):
option = re.escape(option)
return re.match('%s *=' % option, line)
# ==============================================================
# do_ini
@ -141,9 +157,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
if within_section and option:
if state == 'present':
# change the existing option line
if re.match('%s *=' % option, line) \
or re.match('# *%s *=' % option, line) \
or re.match('; *%s *=' % option, line):
if match_opt(option, line):
newline = '%s = %s\n' % (option, value)
changed = ini_lines[index] != newline
ini_lines[index] = newline
@ -154,14 +168,14 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
line = ini_lines[index]
if line.startswith('['):
break
if re.match('%s *=' % option, line):
if match_active_opt(option, line):
del ini_lines[index]
else:
index = index + 1
break
else:
# comment out the existing option line
if re.match('%s *=' % option, line):
if match_active_opt(option, line):
ini_lines[index] = '#%s' % ini_lines[index]
changed = True
break

Loading…
Cancel
Save