Configtool: add --quit and --save commandline switches.
Teach configtool to save ini, board and printer files with the --save commandline switch. Add a feature to Printer and Board to let us pass None for the "values" to save; this causes the class to save the previously loaded settings instead of taking new settings in the argument. Also add --quit switch to tell commandline not to continue to run the GUI. There's not much point in running the gui after many of these switches, but that will change in the future. Add this --quit option to quit early so we can begin to use this new mode for test validation.
This commit is contained in:
parent
ba5447b409
commit
2a6f00454f
|
|
@ -78,6 +78,34 @@ def cmdLoad(arg):
|
|||
print("Expected one of *.ini, board.*.h or printer.*.h.")
|
||||
sys.exit(2)
|
||||
|
||||
def cmdSave(arg):
|
||||
xx, ext = os.path.splitext(arg)
|
||||
fn = os.path.basename(arg)
|
||||
|
||||
if ext == ".ini":
|
||||
if not getSettings(arg).save(arg):
|
||||
print("Failed to save settings file: %s." % arg)
|
||||
sys.exit(2)
|
||||
return
|
||||
|
||||
if ext == ".h":
|
||||
if fn.startswith("board."):
|
||||
global board
|
||||
if not board.saveConfigFile(arg, None):
|
||||
print("Failed trying to save board file: %s." % arg)
|
||||
sys.exit(2)
|
||||
return
|
||||
elif fn.startswith("printer."):
|
||||
global printer
|
||||
if not printer.saveConfigFile(arg, None):
|
||||
print("Failed trying to save printer file: %s." % arg)
|
||||
sys.exit(2)
|
||||
return
|
||||
|
||||
print("Unrecognized file: %s." % arg)
|
||||
print("Expected one of *.ini, board.*.h or printer.*.h.")
|
||||
sys.exit(2)
|
||||
|
||||
def cmdShowAll():
|
||||
names = {"configtool": getSettings(), "board": board, "printer": printer}
|
||||
for namespace in names:
|
||||
|
|
@ -105,7 +133,11 @@ Following options are available for command line automation:
|
|||
loads, only. GUI will overwrite them with the
|
||||
files found in config.h.
|
||||
|
||||
-s <file>, --save=<file> Save the config, printer or board file.
|
||||
|
||||
-a, --show-all Show all loaded variables and values.
|
||||
|
||||
-q, --quit Quit processing without launching the GUI.
|
||||
""" % sys.argv[0])
|
||||
|
||||
def CommandLine(argv):
|
||||
|
|
@ -116,8 +148,8 @@ def CommandLine(argv):
|
|||
global settings, verbose
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(argv, "hvl:a", ["help", "verbose", "load=",
|
||||
"show-all"])
|
||||
opts, args = getopt.getopt(argv, "hvl:as:q", ["help", "verbose", "load=",
|
||||
"show-all", "save=", "quit"])
|
||||
except getopt.GetoptError as err:
|
||||
print(err)
|
||||
print("Use '%s --help' to get help with command line options." %
|
||||
|
|
@ -139,9 +171,15 @@ def CommandLine(argv):
|
|||
elif opt in ("-l", "--load"):
|
||||
cmdLoad(arg)
|
||||
|
||||
elif opt in ("-s", "--save"):
|
||||
cmdSave(arg)
|
||||
|
||||
elif opt in ("-a", "--show-all"):
|
||||
cmdShowAll()
|
||||
|
||||
elif opt in ("-q", "--quit"):
|
||||
sys.exit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
CommandLine(sys.argv[1:])
|
||||
StartGui(getSettings())
|
||||
|
|
|
|||
|
|
@ -333,6 +333,9 @@ class Board:
|
|||
return None
|
||||
|
||||
def saveConfigFile(self, path, values):
|
||||
if not values:
|
||||
values = self.cfgValues
|
||||
|
||||
if self.settings.verbose >= 1:
|
||||
print("Saving board: %s." % path)
|
||||
if self.settings.verbose >= 2:
|
||||
|
|
|
|||
|
|
@ -183,6 +183,9 @@ class Printer:
|
|||
return False
|
||||
|
||||
def saveConfigFile(self, path, values):
|
||||
if not values:
|
||||
values = self.cfgValues
|
||||
|
||||
if self.settings.verbose >= 1:
|
||||
print("Saving printer: %s." % path)
|
||||
if self.settings.verbose >= 2:
|
||||
|
|
|
|||
|
|
@ -116,35 +116,31 @@ class Settings:
|
|||
"uploadspeed": str(self.uploadspeed)
|
||||
}
|
||||
|
||||
def saveSettings(self):
|
||||
def saveSettings(self, inifile = None):
|
||||
if not inifile:
|
||||
inifile = self.inifile
|
||||
|
||||
self.section = "configtool"
|
||||
try:
|
||||
self.cfg.add_section(self.section)
|
||||
except ConfigParser.DuplicateSectionError:
|
||||
pass
|
||||
|
||||
self.cfg.set(self.section, "arduinodir", str(self.arduinodir))
|
||||
self.cfg.set(self.section, "cflags", str(self.cflags))
|
||||
self.cfg.set(self.section, "ldflags", str(self.ldflags))
|
||||
self.cfg.set(self.section, "objcopyflags", str(self.objcopyflags))
|
||||
self.cfg.set(self.section, "programmer", str(self.programmer))
|
||||
self.cfg.set(self.section, "programflags", str(self.programflags))
|
||||
self.cfg.set(self.section, "port", str(self.port))
|
||||
self.cfg.set(self.section, "t0", str(self.t0))
|
||||
self.cfg.set(self.section, "r1", str(self.r1))
|
||||
self.cfg.set(self.section, "numtemps", str(self.numTemps))
|
||||
self.cfg.set(self.section, "maxadc", str(self.maxAdc))
|
||||
self.cfg.set(self.section, "minadc", str(self.minAdc))
|
||||
self.cfg.set(self.section, "uploadspeed", str(self.uploadspeed))
|
||||
values = self.getValues()
|
||||
for k in values.keys():
|
||||
self.cfg.set(self.section, k, values[k])
|
||||
|
||||
try:
|
||||
cfp = open(self.inifile, 'wb')
|
||||
cfp = open(inifile, 'wb')
|
||||
except:
|
||||
print "Unable to open settings file %s for writing." % self.inifile
|
||||
return
|
||||
print("Unable to open settings file %s for writing." % inifile)
|
||||
return False
|
||||
|
||||
self.cfg.write(cfp)
|
||||
cfp.close()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class SettingsDlg(wx.Dialog):
|
||||
def __init__(self, parent, settings):
|
||||
|
|
|
|||
Loading…
Reference in New Issue