update_ini.py: python3 compatibility
This commit is contained in:
parent
d6c8cab6aa
commit
95dc9f07a2
1 changed files with 20 additions and 20 deletions
|
|
@ -8,8 +8,8 @@ import shutil
|
||||||
import linuxcnc
|
import linuxcnc
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
from Tkinter import *
|
from tkinter import *
|
||||||
import tkMessageBox
|
import tkinter.messagebox
|
||||||
|
|
||||||
def copysection(block):
|
def copysection(block):
|
||||||
#Just makes a straight copy of blocks that don't need any work
|
#Just makes a straight copy of blocks that don't need any work
|
||||||
|
|
@ -44,7 +44,7 @@ for opt in sys.argv[1:]:
|
||||||
elif opt == '-f':
|
elif opt == '-f':
|
||||||
force = 1
|
force = 1
|
||||||
elif opt[0] == '-':
|
elif opt[0] == '-':
|
||||||
print "Unknown command line option to update_ini, exiting"
|
print ("Unknown command line option to update_ini, exiting")
|
||||||
exit()
|
exit()
|
||||||
elif os.path.isfile(opt):
|
elif os.path.isfile(opt):
|
||||||
filename = opt
|
filename = opt
|
||||||
|
|
@ -56,13 +56,13 @@ describing the purpose of this script, and giving the user the option
|
||||||
to change their minds\nIf the -f flag is used then no questions will be
|
to change their minds\nIf the -f flag is used then no questions will be
|
||||||
asked and the conversion will proceed blindly"""
|
asked and the conversion will proceed blindly"""
|
||||||
if dialogs:
|
if dialogs:
|
||||||
tkMessageBox.showerror('invalid options', str(t))
|
tkinter.messagebox.showerror('invalid options', str(t))
|
||||||
elif not force:
|
elif not force:
|
||||||
print t
|
print(t)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
if dialogs:
|
if dialogs:
|
||||||
ret = tkMessageBox._show("Confirm automatic update",
|
ret = tkinter.messagebox._show("Confirm automatic update",
|
||||||
"This version of LinuxCNC separates the concepts of Axes and "
|
"This version of LinuxCNC separates the concepts of Axes and "
|
||||||
"Joints which necessitates changes to the INI and HAL files. "
|
"Joints which necessitates changes to the INI and HAL files. "
|
||||||
"The changes required are described here:\n"
|
"The changes required are described here:\n"
|
||||||
|
|
@ -76,7 +76,7 @@ if dialogs:
|
||||||
"files or 'Cancel' to exit LinuxCNC.\n"
|
"files or 'Cancel' to exit LinuxCNC.\n"
|
||||||
"The process can not be automatically reversed, though a "
|
"The process can not be automatically reversed, though a "
|
||||||
"backup version of your entire existing config will be created.",
|
"backup version of your entire existing config will be created.",
|
||||||
tkMessageBox.QUESTION, tkMessageBox.YESNOCANCEL)
|
tkinter.messagebox.QUESTION, tkinter.messagebox.YESNOCANCEL)
|
||||||
if ret == 'cancel': exit(42)
|
if ret == 'cancel': exit(42)
|
||||||
elif ret == 'no': exit(0)
|
elif ret == 'no': exit(0)
|
||||||
|
|
||||||
|
|
@ -88,9 +88,9 @@ try:
|
||||||
except:
|
except:
|
||||||
t = "%s is not a valid ini file" % filename
|
t = "%s is not a valid ini file" % filename
|
||||||
if dialogs:
|
if dialogs:
|
||||||
tkMessageBox.showerror('invalid options', t)
|
tkinter.messagebox.showerror('invalid options', t)
|
||||||
elif not force:
|
elif not force:
|
||||||
print t
|
print(t)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
version = ini.find('EMC', 'VERSION')
|
version = ini.find('EMC', 'VERSION')
|
||||||
|
|
@ -103,21 +103,21 @@ elif version >= THIS_VERSION:
|
||||||
t = """The supplied INI file is already at version %s and should not need
|
t = """The supplied INI file is already at version %s and should not need
|
||||||
updating""" % version
|
updating""" % version
|
||||||
if dialogs:
|
if dialogs:
|
||||||
tkMessageBox.showerror('conversion not needed', t)
|
tkinter.messagebox.showerror('conversion not needed', t)
|
||||||
elif not force:
|
elif not force:
|
||||||
print t
|
print(t)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
if ini.find('KINS', 'JOINTS') and not force and not version == "1.0":
|
if ini.find('KINS', 'JOINTS') and not force and not version == "1.0":
|
||||||
if dialogs:
|
if dialogs:
|
||||||
if tkMessageBox.askquestion("Already Converted",
|
if tkinter.messagebox.askquestion("Already Converted",
|
||||||
"The supplied INI file already has a [KINS] section. this probably "
|
"The supplied INI file already has a [KINS] section. this probably "
|
||||||
"means that it was previously converted by hand. Continue conversion?"
|
"means that it was previously converted by hand. Continue conversion?"
|
||||||
"(Change [EMC]VERSION to %s to suppress these messages) "
|
"(Change [EMC]VERSION to %s to suppress these messages) "
|
||||||
% THIS_VERSION) != 'yes':
|
% THIS_VERSION) != 'yes':
|
||||||
exit(0)
|
exit(0)
|
||||||
else:
|
else:
|
||||||
if raw_input("The supplied INI file already has a [KINS] section."
|
if input("The supplied INI file already has a [KINS] section."
|
||||||
"this probably means that it was previously converted by hand. "
|
"this probably means that it was previously converted by hand. "
|
||||||
"Continue y/N? (Change [EMC]VERSION to %s to suppress these messages) "
|
"Continue y/N? (Change [EMC]VERSION to %s to suppress these messages) "
|
||||||
% THIS_VERSION) != "y":
|
% THIS_VERSION) != "y":
|
||||||
|
|
@ -147,7 +147,7 @@ ini = linuxcnc.ini(old_ini)
|
||||||
halfiles = ini.findall('HAL', 'HALFILE')
|
halfiles = ini.findall('HAL', 'HALFILE')
|
||||||
halfiles += ini.findall('HAL', 'POSTGUI_HALFILE')
|
halfiles += ini.findall('HAL', 'POSTGUI_HALFILE')
|
||||||
halfiles += ['touchy.hal']
|
halfiles += ['touchy.hal']
|
||||||
print "halfiles = ", halfiles
|
print("halfiles = ", halfiles)
|
||||||
|
|
||||||
halpaths = []
|
halpaths = []
|
||||||
for halfile in halfiles:
|
for halfile in halfiles:
|
||||||
|
|
@ -160,9 +160,9 @@ for halfile in halfiles:
|
||||||
elif halfile == "touchy.hal":
|
elif halfile == "touchy.hal":
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print "halfile %s not found\n" % halfile
|
print("halfile %s not found\n" % halfile)
|
||||||
|
|
||||||
print "halpaths = ", halpaths
|
print("halpaths = ", halpaths)
|
||||||
|
|
||||||
if version == "1.0":
|
if version == "1.0":
|
||||||
#Just update the version in the INI
|
#Just update the version in the INI
|
||||||
|
|
@ -313,7 +313,7 @@ if version == "$Revision$" or version < "1.0":
|
||||||
section = re.sub("MAX_ACCELERATION", "MAX_LINEAR_ACCELERATION", section)
|
section = re.sub("MAX_ACCELERATION", "MAX_LINEAR_ACCELERATION", section)
|
||||||
if not re.search("DEFAULT_ACCELERATION", section):
|
if not re.search("DEFAULT_ACCELERATION", section):
|
||||||
section = re.sub("DEFAULT_ACCELERATION", "DEFAULT_LINEAR_ACCELERATION", section)
|
section = re.sub("DEFAULT_ACCELERATION", "DEFAULT_LINEAR_ACCELERATION", section)
|
||||||
print "COORDINATES = %s\n" % ''.join(coordinates)
|
print("COORDINATES = %s\n" % ''.join(coordinates))
|
||||||
section = re.sub("COORDINATES.*", "COORDINATES = %s" % ''.join(coordinates[: joints]), section)
|
section = re.sub("COORDINATES.*", "COORDINATES = %s" % ''.join(coordinates[: joints]), section)
|
||||||
section = re.sub("CYCLE_TIME.*?\n", "", section)
|
section = re.sub("CYCLE_TIME.*?\n", "", section)
|
||||||
section = re.sub("AXES *=.*\n", "", section)
|
section = re.sub("AXES *=.*\n", "", section)
|
||||||
|
|
@ -395,7 +395,7 @@ if version == "$Revision$" or version < "1.0":
|
||||||
else:
|
else:
|
||||||
subs.update({'\[AXIS_%i\]' % J : '[JOINT_%i]' % J})
|
subs.update({'\[AXIS_%i\]' % J : '[JOINT_%i]' % J})
|
||||||
else:
|
else:
|
||||||
print "File parsing error, found an [AXIS_%i] section, but no content" % J
|
print("File parsing error, found an [AXIS_%i] section, but no content" % J)
|
||||||
exit()
|
exit()
|
||||||
# We no longer need the [AXIS_N] data
|
# We no longer need the [AXIS_N] data
|
||||||
for j in range(0,8):
|
for j in range(0,8):
|
||||||
|
|
@ -549,8 +549,8 @@ if version < "1.1":
|
||||||
})
|
})
|
||||||
|
|
||||||
if subs == {}:
|
if subs == {}:
|
||||||
print """This file does not need converting, and furthermore execution
|
print("""This file does not need converting, and furthermore execution
|
||||||
should never have reached this spot"""
|
should never have reached this spot""")
|
||||||
else:
|
else:
|
||||||
for halfile in halpaths:
|
for halfile in halpaths:
|
||||||
halstring = open(halfile,'r').read()
|
halstring = open(halfile,'r').read()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue