Skip to content

Commit 24251e2

Browse files
committed
update_ini: fix \n to work also from upgrading <1.0
1 parent c7afc84 commit 24251e2

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/emc/ini/update_ini.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
def copysection(block):
1616
#Just makes a straight copy of blocks that don't need any work
17-
regex = r"^\s*\[%s\](\n(?:^(?!\[).*\n?)*)" % block
17+
regex = r"^\s*\[%s\](\n(?:^(?!\[).*(?:\n(?=^(?!\[))|$))*)" % block
1818
section = re.search(regex, inistring, re.M)
19-
newini.write("[%s]" % block)
19+
newini.write("\n[%s]" % block)
2020
if section is not None:
2121
newini.write(section.group(1))
2222
all_sections.remove(block)
@@ -41,7 +41,7 @@ def insert_after(key, new_line, section):
4141
return section[:line_end + 1] + new_line + section[line_end + 1:]
4242

4343
def find_section(section, inistring):
44-
section = re.search(r"(?:^|\n)[ \t]*(?!#)\[{}\](.+?\n)(?=\[|$)".format(section), inistring, re.DOTALL)
44+
section = re.search(r"^\s*\[%s\](\n(?:^(?!\[).*(?:\n(?=^(?!\[))|$))*)" % section, inistring, re.M)
4545
if section: section = section.group(1)
4646
return section
4747

@@ -190,7 +190,7 @@ def find_section(section, inistring):
190190
############ Convert INI files ############
191191
###########################################
192192

193-
def ini_preamble():
193+
def ini_preamble(version):
194194
"""
195195
The part which is equal for the conversions up from version 1.1
196196
"""
@@ -220,26 +220,18 @@ def ini_preamble():
220220
newini.write("[EMC]")
221221
if section != None:
222222
if version != "0.0":
223-
section = re.sub("VERSION (.+)", "VERSION = %s" % THIS_VERSION, section)
223+
section = re.sub("VERSION (.+)", "VERSION = %s" % version, section)
224224
else:
225225
newini.write("# The version string for this INI file.\n")
226-
newini.write("VERSION = %s\n" % THIS_VERSION)
226+
newini.write("VERSION = %s\n" % version)
227227
newini.write(section)
228228
else:
229-
newini.write("VERSION = %s\n" % THIS_VERSION)
229+
newini.write("VERSION = %s\n" % version)
230230

231231
return inistring, newini, all_sections
232232

233-
if version == "1.0":
234-
#Just update the version in the INI
235-
inistring = open(filename,'r').read()
236-
newini = open(filename, 'w')
237-
inistring = re.sub("VERSION *= *(.*)", "VERSION = %s" % THIS_VERSION, inistring)
238-
newini.write(inistring)
239-
newini.close()
240-
241233
if version == "$Revision$" or version < "1.0":
242-
inistring, newini, all_sections = ini_preamble()
234+
inistring, newini, all_sections = ini_preamble("1.0")
243235
#These sections don't need any work.
244236
copysection("DISPLAY")
245237
copysection("FILTER")
@@ -447,8 +439,16 @@ def ini_preamble():
447439
#That's the INI file done:
448440
newini.close()
449441

442+
if version == "1.0":
443+
#Just update the version in the INI
444+
inistring = open(filename,'r').read()
445+
newini = open(filename, 'w')
446+
inistring = re.sub("VERSION *= *(.*)", "VERSION = 1.1", inistring)
447+
newini.write(inistring)
448+
newini.close()
449+
450450
if version < "1.2":
451-
inistring, newini, all_sections = ini_preamble()
451+
inistring, newini, all_sections = ini_preamble("1.2")
452452

453453
all_sections.remove("DISPLAY")
454454
section = find_section("DISPLAY", inistring)

0 commit comments

Comments
 (0)