11#!/usr/bin/env python3
22
3- THIS_VERSION = "1.1 "
3+ THIS_VERSION = "1.2 "
44
55import sys
66import os
@@ -21,7 +21,7 @@ def copysection(block):
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 " )
2525
2626def writeifexists (file , section , src_item , dest_item = "None" ):
2727 #Writes a new entry to the file, but only if it exists
@@ -62,25 +62,6 @@ def writeifexists(file, section, src_item, dest_item = "None"):
6262 print (t )
6363 exit ()
6464
65- if dialogs :
66- ret = messagebox ._show ("Confirm automatic update" ,
67- "This version of LinuxCNC separates the concepts of Axes and "
68- "Joints which necessitates changes to the INI and HAL files. "
69- "The changes required are described here:\n "
70- "http://linuxcnc.org/docs/2.9/html/ in the section "
71- "'Getting Started with LinuxCNC' -> 'Updating LinuxCNC'\n "
72- "The [EMC]VERSION data in your INI file indicates that your "
73- "configuration requires update.\n "
74- "A script exists that can attempt to automatically "
75- "reconfigure your configuration files.\n Press 'Yes' to perform "
76- "the conversion, 'No' to continue with the current configuration "
77- "files or 'Cancel' to exit LinuxCNC.\n "
78- "The process can not be automatically reversed, though a "
79- "backup version of your entire existing config will be created." ,
80- messagebox .QUESTION , messagebox .YESNOCANCEL )
81- if ret == 'cancel' : exit (42 )
82- elif ret == 'no' : exit (0 )
83-
8465# We want to work with the base INI file here, not the expanded version if #include is used
8566filename = re .sub (r'\.expanded' , '' , filename )
8667
@@ -109,20 +90,44 @@ def writeifexists(file, section, src_item, dest_item = "None"):
10990 print (t )
11091 exit ()
11192
112- if ini .find ('KINS' , 'JOINTS' ) and not force and not version == "1.0" :
113- if dialogs :
114- if messagebox .askquestion ("Already Converted" ,
115- "The supplied INI file already has a [KINS] section. this probably "
116- "means that it was previously converted by hand. Continue conversion?"
117- "(Change [EMC]VERSION to %s to suppress these messages) "
118- % THIS_VERSION ) != 'yes' :
119- exit (0 )
120- else :
121- if input ("The supplied INI file already has a [KINS] section."
122- "this probably means that it was previously converted by hand. "
123- "Continue y/N? (Change [EMC]VERSION to %s to suppress these messages) "
124- % THIS_VERSION ) != "y" :
125- exit (0 )
93+ # Show start message with abort option
94+ if dialogs :
95+ ret = ''
96+ if version == "1.0" :
97+ ret = messagebox ._show ("Confirm automatic update" ,
98+ "This version of LinuxCNC separates the concepts of Axes and "
99+ "Joints which necessitates changes to the INI and HAL files. "
100+ "The changes required are described here:\n "
101+ "http://linuxcnc.org/docs/2.9/html/ in the section "
102+ "'Getting Started with LinuxCNC' -> 'Updating LinuxCNC'\n "
103+ "The [EMC]VERSION data in your INI file indicates that your "
104+ "configuration requires update.\n "
105+ "A script exists that can attempt to automatically "
106+ "reconfigure your configuration files.\n Press 'Yes' to perform "
107+ "the conversion, 'No' to continue with the current configuration "
108+ "files or 'Cancel' to exit LinuxCNC.\n "
109+ "The process can not be automatically reversed, though a "
110+ "backup version of your entire existing config will be created." ,
111+ messagebox .QUESTION , messagebox .YESNOCANCEL )
112+ if ret == 'cancel' : exit (42 )
113+ elif ret == 'no' : exit (0 )
114+
115+ # Version specific message
116+ if version == "1.0" :
117+ if ini .find ('KINS' , 'JOINTS' ) and not force and not version == "1.0" :
118+ if dialogs :
119+ if messagebox .askquestion ("Already Converted" ,
120+ "The supplied INI file already has a [KINS] section. This probably "
121+ "means that it was previously converted by hand. Continue conversion?"
122+ "(Change [EMC]VERSION to %s to suppress these messages) "
123+ % THIS_VERSION ) != 'yes' :
124+ exit (0 )
125+ else :
126+ if input ("The supplied INI file already has a [KINS] section."
127+ "This probably means that it was previously converted by hand. "
128+ "Continue y/N? (Change [EMC]VERSION to %s to suppress these messages) "
129+ % THIS_VERSION ) != "y" :
130+ exit (0 )
126131
127132# Looks like we are good to go, so first let's put the original configs
128133# somewhere safe.
@@ -165,16 +170,14 @@ def writeifexists(file, section, src_item, dest_item = "None"):
165170
166171print ("halpaths = " , halpaths )
167172
168- if version == "1.0" :
169- #Just update the version in the INI
170- inistring = open (filename ,'r' ).read ()
171- newini = open (filename , 'w' )
172- inistring = re .sub ("VERSION *= *(.*)" , "VERSION = %s" % THIS_VERSION , inistring )
173- newini .write (inistring )
174- newini .close ()
173+ ###########################################
174+ ############ Convert INI files ############
175+ ###########################################
175176
176- if version == "$Revision$" or version < "1.0" :
177-
177+ def ini_preamble ():
178+ """
179+ The part which is equal for the conversions up from version 1.1
180+ """
178181 inistring = open (filename ,'r' ).read ()
179182 newini = open (filename , 'w' )
180183 # Get a list of all sections
@@ -198,7 +201,7 @@ def writeifexists(file, section, src_item, dest_item = "None"):
198201 all_sections .remove ("EMC" )
199202 section = re .search (r"\[EMC\](.+?)\n\[" , inistring , re .DOTALL )
200203 if section : section = section .group (1 )
201- newini .write ("[EMC]\n " )
204+ newini .write ("[EMC]" )
202205 if section != None :
203206 if version != "0.0" :
204207 section = re .sub ("VERSION (.+)" , "VERSION = %s" % THIS_VERSION , section )
@@ -209,6 +212,18 @@ def writeifexists(file, section, src_item, dest_item = "None"):
209212 else :
210213 newini .write ("VERSION = %s\n " % THIS_VERSION )
211214
215+ return inistring , newini , all_sections
216+
217+ if version == "1.0" :
218+ #Just update the version in the INI
219+ inistring = open (filename ,'r' ).read ()
220+ newini = open (filename , 'w' )
221+ inistring = re .sub ("VERSION *= *(.*)" , "VERSION = %s" % THIS_VERSION , inistring )
222+ newini .write (inistring )
223+ newini .close ()
224+
225+ if version == "$Revision$" or version < "1.0" :
226+ inistring , newini , all_sections = ini_preamble ()
212227 #These sections don't need any work.
213228 copysection ("DISPLAY" )
214229 copysection ("FILTER" )
@@ -416,11 +431,67 @@ def writeifexists(file, section, src_item, dest_item = "None"):
416431 #That's the INI file done:
417432 newini .close ()
418433
434+ if version < "1.2" :
435+ inistring , newini , all_sections = ini_preamble ()
436+
437+ all_sections .remove ("DISPLAY" )
438+ section = re .search (r"\[DISPLAY\](.+?)\n\[" , inistring , re .DOTALL )
439+ if section : section = section .group (1 )
440+ newini .write ("\n [DISPLAY]\n " )
441+ if section != None :
442+ if re .search ("MIN_SPINDLE_OVERRIDE" , section ):
443+ section = re .sub ("MIN_SPINDLE_OVERRIDE" , "MIN_SPINDLE_0_OVERRIDE" , section )
444+ if re .search ("MAX_SPINDLE_OVERRIDE" , section ):
445+ section = re .sub ("MAX_SPINDLE_OVERRIDE" , "MAX_SPINDLE_0_OVERRIDE" , section )
446+ if re .search ("DEFAULT_SPINDLE_SPEED" , section ):
447+ section = re .sub ("DEFAULT_SPINDLE_SPEED" , "DEFAULT_SPINDLE_0_SPEED" , section )
448+ if re .search ("MIN_SPINDLE_SPEED" , section ):
449+ section = re .sub ("MIN_SPINDLE_SPEED" , "MIN_SPINDLE_0_SPEED" , section )
450+ if re .search ("MAX_SPINDLE_SPEED" , section ):
451+ section = re .sub ("MAX_SPINDLE_SPEED" , "MAX_SPINDLE_0_SPEED" , section )
452+ if re .search ("MIN_VELOCITY" , section ):
453+ section = re .sub ("MIN_VELOCITY" , "MIN_LINEAR_VELOCITY" , section )
454+ newini .write (section )
455+
456+ # TODO update-ini 1.1 --> 1.2:
457+ #
458+ # [DISPLAY]
459+ # MIN_SPINDLE_OVERRIDE -> MIN_SPINDLE_0_OVERRIDE
460+ # MAX_SPINDLE_OVERRIDE -> MAX_SPINDLE_0_OVERRIDE
461+ # DEFAULT_SPINDLE_SPEED -> DEFAULT_SPINDLE_0_SPEED
462+ # MIN_SPINDLE_SPEED -> MIN_SPINDLE_0_SPEED
463+ # MAX_SPINDLE_SPEED -> MAX_SPINDLE_0_SPEED
464+ #
465+ # copy [TRAJ]DEFAULT_LINEAR_VELOCITY -> [DISPLAY]DEFAULT_LINEAR_VELOCITY
466+ # move [TRAJ]MIN_LINEAR_VELOCITY -> [DISPLAY]MIN_LINEAR_VELOCITY
467+ # rename [TRAJ, DISPLAY]MIN_VELOCITY --> MIN_LINEAR_VELOCITY
468+ # copy [TRAJ]MAX_LINEAR_VELOCITY -> [DISPLAY]MAX_LINEAR_VELOCITY
469+
470+ #These sections don't need any work.
471+ copysection ("FILTER" )
472+ copysection ("RS274NGC" )
473+ copysection ("PYTHON" )
474+ copysection ("EMCMOT" )
475+ copysection ("TASK" )
476+ copysection ("HAL" )
477+ copysection ("HALUI" )
478+ copysection ("TRAJ" )
479+ copysection ("EMCIO" )
480+
481+ # If there were any custom sections, tag them on the end.
482+ while all_sections :
483+ copysection (all_sections [0 ])
484+
485+ #That's the INI file done:
486+ newini .close ()
419487
420488
421- # Now change all the pin names etc in the linked HAL files.
422- # Any machine can be jogged in world mode (in theory) but joint-mode jog-enable
423- # is not auto-linked for safety.
489+ ###########################################
490+ ############ Convert HAL files ############
491+ ###########################################
492+ # Now change all the pin names etc in the linked HAL files.
493+ # Any machine can be jogged in world mode (in theory)
494+ # but joint-mode jog-enable is not auto-linked for safety.
424495
425496if version == "$Revision$" or version < "1.0" :
426497
0 commit comments