- made --shellvars into --shellvar and make it only one list of commands passed to the Tcl. The list is separated by comma but without spaces. The variables are accessed in Tcl with the names shellvar_x where x is the index in the list of command comma separated values

- fixed an issue in the TclShell that generated an exception IndexError which crashed the software
This commit is contained in:
Marius Stanciu 2019-09-17 18:37:34 +03:00
parent 71b945c05e
commit 608f1dd958
3 changed files with 32 additions and 25 deletions

View File

@ -80,13 +80,13 @@ class App(QtCore.QObject):
# Get Cmd Line Options
cmd_line_shellfile = ''
cmd_line_shellvars = ''
cmd_line_shellvar = ''
cmd_line_help = "FlatCam.py --shellfile=<cmd_line_shellfile>\nFlatCam.py --shellvars=<cmd_line_shellvars"
cmd_line_help = "FlatCam.py --shellfile=<cmd_line_shellfile>\nFlatCam.py --shellvar=<cmd_line_shellvar>"
try:
# Multiprocessing pool will spawn additional processes with 'multiprocessing-fork' flag
cmd_line_options, args = getopt.getopt(sys.argv[1:], "h:", ["shellfile=",
"shellvars=",
"shellvar=",
"multiprocessing-fork="])
except getopt.GetoptError:
print(cmd_line_help)
@ -97,8 +97,8 @@ class App(QtCore.QObject):
sys.exit()
elif opt == '--shellfile':
cmd_line_shellfile = arg
elif opt == '--shellvars':
cmd_line_shellvars = arg
elif opt == '--shellvar':
cmd_line_shellvar = arg
# ## Logging ###
log = logging.getLogger('base')
@ -2412,26 +2412,28 @@ class App(QtCore.QObject):
except Exception as ext:
print("ERROR: ", ext)
sys.exit(2)
elif self.cmd_line_shellvars:
elif self.cmd_line_shellvar:
try:
with open(self.cmd_line_shellvars, "r") as myfile:
if show_splash:
self.splash.showMessage('%s: %ssec\n%s' % (
_("Canvas initialization started.\n"
"Canvas initialization finished in"), '%.2f' % self.used_time,
_("Reading Shell vars ...")),
alignment=Qt.AlignBottom | Qt.AlignLeft,
color=QtGui.QColor("gray"))
cmd_line_shellvars_text = myfile.read()
for line in cmd_line_shellvars_text.splitlines():
var, __, var_value = line.partition('=')
var = var.replace(' ', '')
var_value = var_value.replace(' ', '')
command_tcl = 'set {var} {var_value}'.format(var=var, var_value=var_value)
self.shell._sysShell.exec_command(command_tcl, no_echo=True)
cnt = 0
command_tcl = 0
for i in self.cmd_line_shellvar.split(','):
if i is not None:
try:
command_tcl = eval(i)
except:
command_tcl = i
command_tcl_formatted = 'set shellvar_{nr} {cmd}'.format(cmd=str(command_tcl), nr=str(cnt))
cnt += 1
# if there are Windows paths then replace the path separator with a Unix like one
if sys.platform == 'win32':
command_tcl_formatted = command_tcl_formatted.replace('\\', '/')
self.shell._sysShell.exec_command(command_tcl_formatted, no_echo=True)
except Exception as ext:
print("ERROR: ", ext)
sys.exit(2)
# accept some type file as command line parameter: FlatCAM project, FlatCAM preferences or scripts
# the path/file_name must be enclosed in quotes if it contain spaces
if App.args:

View File

@ -18,6 +18,8 @@ CAD program, and create G-Code for Isolation routing.
- fixed an bug where the pywrapcp name from Google OR-Tools is not defined; fix issue #316
- if FlatCAM is started with the 'quit' or 'exit' as argument it will close immediately and it will close also another instance of FlatCAM that may be running
- added a new command line parameter for FlatCAM named '--shellvars' which can load a text file with variables for Tcl Shell in the format: one variable assignment per line and looking like: 'a=3' without quotes
- made --shellvars into --shellvar and make it only one list of commands passed to the Tcl. The list is separated by comma but without spaces. The variables are accessed in Tcl with the names shellvar_x where x is the index in the list of command comma separated values
- fixed an issue in the TclShell that generated an exception IndexError which crashed the software
16.09.2019

View File

@ -142,10 +142,13 @@ class TermWidget(QWidget):
self._append_to_browser('in', '> ' + text + '\n')
if len(self._history) < 2 or self._history[-2] != text: # don't insert duplicating items
if text[-1] == '\n':
self._history.insert(-1, text[:-1])
else:
self._history.insert(-1, text)
try:
if text[-1] == '\n':
self._history.insert(-1, text[:-1])
else:
self._history.insert(-1, text)
except IndexError:
return
self._historyIndex = len(self._history) - 1