@@ -40,6 +40,11 @@ def insert_after(key, new_line, section):
4040 new_line += "\n "
4141 return section [:line_end + 1 ] + new_line + section [line_end + 1 :]
4242
43+ def find_section (section , inistring ):
44+ section = re .search (r"(?:^|\n)[ \t]*(?!#)\[{}\](.+?\n)(?=\[|$)" .format (section ), inistring , re .DOTALL )
45+ if section : section = section .group (1 )
46+ return section
47+
4348force = 0
4449dialogs = 0
4550subs = {}
@@ -446,9 +451,7 @@ def ini_preamble():
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 ini_preamble():
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,17 @@ def ini_preamble():
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 ("MIN_LINEAR_VELOCITY" , section ):
512+ section = re .sub ("MIN_LINEAR_VELOCITY.*\n ?" , "# moved MIN_LINEAR_VELOCITY to [DISPLAY]\n " , section )
513+ if re .search ("MIN_VELOCITY" , section ):
514+ section = re .sub ("MIN_VELOCITY.*\n ?" , "# moved MIN_VELOCITY to DISPLAY]MIN_LINEAR_VELOCITY\n " , section )
515+ newini .write ("\n [TRAJ]" )
516+ newini .write (section )
517+
518+ # Copy the remaining sections
510519 while all_sections :
511520 copysection (all_sections [0 ])
512521
0 commit comments