From 0c8ae903e9647fc144bcf31823d804ddbb6c874b Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Tue, 19 Apr 2016 16:19:39 -0400 Subject: [PATCH] Configtool: add --load switch to load printer, board or ini. Teach configtool command line functions to load the printer, board or ini file settings into internal classes. For now this only exercises the "load" functionality of the classes, but with -vv you can also see the results of the load dumped to the console. --- configtool.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/configtool.py b/configtool.py index 7002c0a..6f2d8bd 100755 --- a/configtool.py +++ b/configtool.py @@ -26,6 +26,8 @@ import inspect from configtool.settings import Settings from configtool.gui import StartGui +from configtool.board import Board +from configtool.printer import Printer cmdFolder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( @@ -33,6 +35,8 @@ cmdFolder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( verbose = 0 settings = None +board = None +printer = None def getSettings(arg = None): global settings @@ -42,7 +46,37 @@ def getSettings(arg = None): return settings def cmdLoad(arg): - print("Want to load %s, but don't know how.\n" % arg) + xx, ext = os.path.splitext(arg) + fn = os.path.basename(arg) + + if ext == ".ini": + settings = getSettings(arg) + if not settings.loaded: + print("Failed to load settings file: %s." % arg) + sys.exit(2) + return + + if ext == ".h": + if fn.startswith("board."): + global board + board = Board(getSettings()) + ok, fn = board.loadConfigFile(arg) + if not ok: + print("Failed trying to load board file: %s." % fn) + sys.exit(2) + return + elif fn.startswith("printer."): + global printer + printer = Printer(getSettings()) + ok, fn = printer.loadConfigFile(arg) + if not ok: + print("Failed trying to load printer file: %s" % fn) + sys.exit(2) + return + + print("Unrecognized file: %s." % arg) + print("Expected one of *.ini, board.*.h or printer.*.h.") + sys.exit(2) def cmdHelp(): print("""Usage: %s [options] @@ -56,7 +90,12 @@ Following options are available for command line automation: to get even more output. -l , --load= Load a specific printer config, board config - or .ini file. + or .ini file. Can be applied multiple times to + load multiple files. + + Content of this file is valid before the GUI + loads, only. GUI will overwrite them with the + files found in config.h. """ % sys.argv[0]) def CommandLine(argv):