From f9b158ebb3d81c923461981d2b087989c284c2d4 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 30 May 2018 21:18:49 +0200 Subject: Add tool helper for loading/saving .config files Removes repeated KCONFIG_CONFIG boilerplate. Also make allyesconfig use KCONFIG_CONFIG when writing (oversight), and document the sys.exit() behavior for standard_kconfig(). --- kconfiglib.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 1b57821..1a1d629 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4487,14 +4487,28 @@ def unescape(s): def standard_kconfig(): """ - Helper for implementing tools. Loads either a top-level Kconfig specified - as an argument, or "Kconfig" otherwise. Returns the Kconfig instance. + Helper for tools. Loads the top-level Kconfig specified as the first + command-line argument, or "Kconfig" if there are no command-line arguments. + Returns the Kconfig instance. + + Exits with sys.exit() (which raises a SystemExit exception) and prints a + usage note to stderr if more than one command-line argument is passed. """ if len(sys.argv) > 2: sys.exit("usage: {} [Kconfig]".format(sys.argv[0])) return Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1]) +def standard_config_filename(): + """ + Helper for tools. Returns the value of KCONFIG_CONFIG (which specifies the + .config file to load/save) if it is set, and ".config" otherwise. + """ + config_filename = os.environ.get("KCONFIG_CONFIG") + if config_filename is not None: + return config_filename + return ".config" + # # Internal functions # -- cgit v1.2.3