Skip to content

Commit 76b1ddd

Browse files
committed
update_ini: fix keep emtpy lines at the end of a section
1 parent f6ccc63 commit 76b1ddd

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/emc/ini/update_ini.py

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

1515
def copysection(block):
1616
#Just makes a straight copy of blocks that don't need any work
17-
regex = r"^\s*\[%s\](.+?)(?:^\s*\[|\Z)" % block
18-
section = re.search(regex, inistring, re.M | re.DOTALL)
19-
newini.write("\n[%s]" % block)
20-
if section != None:
17+
regex = r"^\s*\[%s\](\n(?:^(?!\[).*\n?)*)" % block
18+
section = re.search(regex, inistring, re.M)
19+
newini.write("[%s]" % block)
20+
if section is not None:
2121
newini.write(section.group(1))
2222
all_sections.remove(block)
2323
else:
24-
newini.write("\n#No Content\n")
24+
newini.write("\n#No Content\n\n")
2525

2626
def writeifexists(file, section, src_item, dest_item = "None"):
2727
#Writes a new entry to the file, but only if it exists
@@ -435,9 +435,10 @@ def ini_preamble():
435435
inistring, newini, all_sections = ini_preamble()
436436

437437
all_sections.remove("DISPLAY")
438-
section = re.search(r"\[DISPLAY\](.+?)\n\[", inistring, re.DOTALL)
438+
section = re.search(r"\[DISPLAY\](.+?\n)(?=\[)", inistring, re.DOTALL)
439+
439440
if section: section = section.group(1)
440-
newini.write("\n[DISPLAY]\n")
441+
newini.write("\n[DISPLAY]")
441442
if section != None:
442443
if re.search("MIN_SPINDLE_OVERRIDE", section):
443444
section = re.sub("MIN_SPINDLE_OVERRIDE", "MIN_SPINDLE_0_OVERRIDE", section)

0 commit comments

Comments
 (0)