Skip to content

Commit 1d4850e

Browse files
committed
update_ini: remove no longer needed values from TRAJ
1 parent d54e3ee commit 1d4850e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/emc/ini/update_ini.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,16 @@ def insert_after(key, new_line, section):
442442
new_line += "\n"
443443
return section[:line_end + 1] + new_line + section[line_end + 1:]
444444

445+
def find_section(section, inistring):
446+
section = re.search(r"(?:^|\n)[ \t]*(?!#)\[{}\](.+?\n)(?=\[|$)".format(section), inistring, re.DOTALL)
447+
if section: section = section.group(1)
448+
return section
449+
445450
if version < "1.2":
446451
inistring, newini, all_sections = ini_preamble()
447452

448453
all_sections.remove("DISPLAY")
449-
section = re.search(r"(?:^|\n)[ \t]*(?!#)\[DISPLAY\](.+?\n)(?=\[|$)", inistring, re.DOTALL)
450-
451-
if section: section = section.group(1)
454+
section = find_section("DISPLAY", inistring)
452455
newini.write("\n[DISPLAY]")
453456
if section != None:
454457
if re.search("MIN_SPINDLE_OVERRIDE", section):
@@ -463,22 +466,21 @@ def insert_after(key, new_line, section):
463466
section = re.sub("MAX_SPINDLE_SPEED", "MAX_SPINDLE_0_SPEED", section)
464467
if re.search("MIN_VELOCITY", section):
465468
section = re.sub("MIN_VELOCITY", "MIN_LINEAR_VELOCITY", section)
466-
467-
468469
# Copy values from TRAJ
469470
if not re.search("DEFAULT_LINEAR_VELOCITY", section):
470471
val = ini.find("TRAJ", "DEFAULT_LINEAR_VELOCITY")
471472
if val:
472473
section = insert_after("MAX_LINEAR_VELOCITY", f"DEFAULT_LINEAR_VELOCITY = {val}\n" , section)
473474
if not re.search("MIN_LINEAR_VELOCITY", section):
474475
val = ini.find("TRAJ", "MIN_LINEAR_VELOCITY")
476+
if val is None:
477+
val = ini.find("TRAJ", "MIN_VELOCITY")
475478
if val:
476479
section = insert_after("MAX_LINEAR_VELOCITY", f"MIN_LINEAR_VELOCITY = {val}\n" , section)
477480
if not re.search("MAX_LINEAR_VELOCITY", section):
478481
val = ini.find("TRAJ", "MAX_LINEAR_VELOCITY")
479482
if val:
480483
section = insert_after("MIN_LINEAR_VELOCITY", f"MAX_LINEAR_VELOCITY = {val}\n" , section)
481-
482484
newini.write(section)
483485

484486
# TODO update-ini 1.1 --> 1.2:
@@ -503,10 +505,19 @@ def insert_after(key, new_line, section):
503505
copysection("TASK")
504506
copysection("HAL")
505507
copysection("HALUI")
506-
copysection("TRAJ")
507-
copysection("EMCIO")
508-
509-
# If there were any custom sections, tag them on the end.
508+
# copysection("TRAJ")
509+
all_sections.remove("TRAJ")
510+
section = find_section("TRAJ", inistring)
511+
if re.search("DEFAULT_LINEAR_VELOCITY", section):
512+
section = re.sub("DEFAULT_LINEAR_VELOCITY.*\n?", "# moved DEFAULT_LINEAR_VELOCITY to [DISPLAY]\n", section)
513+
if re.search("MIN_LINEAR_VELOCITY", section):
514+
section = re.sub("MIN_LINEAR_VELOCITY.*\n?", "# moved MIN_LINEAR_VELOCITY to [DISPLAY]\n", section)
515+
if re.search("MIN_VELOCITY", section):
516+
section = re.sub("MIN_VELOCITY.*\n?", "# moved MIN_VELOCITY to DISPLAY]MIN_LINEAR_VELOCITY\n", section)
517+
newini.write("\n[TRAJ]")
518+
newini.write(section)
519+
520+
# Copy the remaining sections
510521
while all_sections:
511522
copysection(all_sections[0])
512523

0 commit comments

Comments
 (0)