diff options
| -rwxr-xr-x | allnoconfig.py | 6 | ||||
| -rwxr-xr-x | allyesconfig.py | 2 | ||||
| -rw-r--r-- | kconfiglib.py | 18 | ||||
| -rwxr-xr-x | menuconfig.py | 7 | ||||
| -rwxr-xr-x | oldconfig.py | 7 |
5 files changed, 22 insertions, 18 deletions
diff --git a/allnoconfig.py b/allnoconfig.py index a840ea6..f90cb28 100755 --- a/allnoconfig.py +++ b/allnoconfig.py @@ -28,11 +28,7 @@ def main(): if sym.orig_type in BOOL_TRI: sym.set_value(2 if sym.is_allnoconfig_y else 0) - config_filename = os.environ.get("KCONFIG_CONFIG") - if config_filename is None: - config_filename = ".config" - - kconf.write_config(config_filename) + kconf.write_config(kconfiglib.standard_config_filename()) if __name__ == "__main__": main() diff --git a/allyesconfig.py b/allyesconfig.py index a0eb01d..f99171c 100755 --- a/allyesconfig.py +++ b/allyesconfig.py @@ -70,7 +70,7 @@ def main(): if not changed: break - kconf.write_config(".config") + kconf.write_config(kconfiglib.standard_config_filename()) if __name__ == "__main__": main() 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 # diff --git a/menuconfig.py b/menuconfig.py index 584bf8e..ff27d17 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -96,7 +96,7 @@ from kconfiglib import Kconfig, \ AND, OR, NOT, \ expr_value, split_expr, \ TRI_TO_STR, TYPE_TO_STR, \ - standard_kconfig + standard_kconfig, standard_config_filename # @@ -299,10 +299,7 @@ def menuconfig(kconf): global _conf_changed - _config_filename = os.environ.get("KCONFIG_CONFIG") - if _config_filename is None: - _config_filename = ".config" - + _config_filename = standard_config_filename() if os.path.exists(_config_filename): _conf_changed = False diff --git a/oldconfig.py b/oldconfig.py index 70a3f5f..546da02 100755 --- a/oldconfig.py +++ b/oldconfig.py @@ -101,7 +101,7 @@ # Configuration written to .config from __future__ import print_function from kconfiglib import Kconfig, Symbol, Choice, BOOL, TRISTATE, HEX, \ - standard_kconfig + standard_kconfig, standard_config_filename import os import sys @@ -302,10 +302,7 @@ def do_oldconfig_for_node(node): def main(): kconf = standard_kconfig() - config_filename = os.environ.get("KCONFIG_CONFIG") - if config_filename is None: - config_filename = ".config" - + config_filename = standard_config_filename() if not os.path.exists(config_filename): sys.exit("{}: '{}' does not exist" .format(sys.argv[0], config_filename)) |
