diff options
| -rw-r--r-- | README.rst | 6 | ||||
| -rwxr-xr-x | alldefconfig.py | 2 | ||||
| -rwxr-xr-x | allmodconfig.py | 4 | ||||
| -rwxr-xr-x | allnoconfig.py | 10 | ||||
| -rwxr-xr-x | allyesconfig.py | 4 | ||||
| -rwxr-xr-x | guiconfig.py | 2 | ||||
| -rw-r--r-- | kconfiglib.py | 34 | ||||
| -rwxr-xr-x | listnewconfig.py | 2 | ||||
| -rwxr-xr-x | menuconfig.py | 2 | ||||
| -rwxr-xr-x | oldconfig.py | 2 | ||||
| -rwxr-xr-x | olddefconfig.py | 2 |
11 files changed, 42 insertions, 28 deletions
@@ -280,12 +280,12 @@ For HTML output, add ``-w``: This will also work after installing Kconfiglib with ``pip(3)``. -Documentation for the ``menuconfig`` and ``guiconfig`` interfaces can be viewed -in the same way: +Documentation for other modules can be viewed in the same way (though a plain +``--help`` will work when they're run as executables): .. code:: sh - $ pydoc3 menuconfig/guiconfig + $ pydoc(3) menuconfig/guiconfig/... A good starting point for learning the library is to read the module docstring (which you could also just read directly at the beginning of `kconfiglib.py diff --git a/alldefconfig.py b/alldefconfig.py index 5082fcb..fab8385 100755 --- a/alldefconfig.py +++ b/alldefconfig.py @@ -18,7 +18,7 @@ import kconfiglib def main(): - kconf = kconfiglib.standard_kconfig() + kconf = kconfiglib.standard_kconfig(__doc__) kconfiglib.load_allconfig(kconf, "alldef.config") print(kconf.write_config()) diff --git a/allmodconfig.py b/allmodconfig.py index 9ae0b3b..7525805 100755 --- a/allmodconfig.py +++ b/allmodconfig.py @@ -11,13 +11,13 @@ in the KCONFIG_CONFIG environment variable. Usage for the Linux kernel: - $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/allmodconfig.py + $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allmodconfig.py """ import kconfiglib def main(): - kconf = kconfiglib.standard_kconfig() + kconf = kconfiglib.standard_kconfig(__doc__) # See allnoconfig.py kconf.warn = False diff --git a/allnoconfig.py b/allnoconfig.py index e162ccb..1a763f9 100755 --- a/allnoconfig.py +++ b/allnoconfig.py @@ -11,16 +11,16 @@ in the KCONFIG_CONFIG environment variable. Usage for the Linux kernel: - $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/allmodconfig.py - -See the examples/allnoconfig_walk.py example script for another way to -implement this script. + $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allnoconfig.py """ + +# See examples/allnoconfig_walk.py for another way to implement this script. + import kconfiglib def main(): - kconf = kconfiglib.standard_kconfig() + kconf = kconfiglib.standard_kconfig(__doc__) # Avoid warnings that would otherwise get printed by Kconfiglib for the # following: diff --git a/allyesconfig.py b/allyesconfig.py index e19ab31..4967605 100755 --- a/allyesconfig.py +++ b/allyesconfig.py @@ -11,13 +11,13 @@ in the KCONFIG_CONFIG environment variable. Usage for the Linux kernel: - $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/allmodconfig.py + $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allyesconfig.py """ import kconfiglib def main(): - kconf = kconfiglib.standard_kconfig() + kconf = kconfiglib.standard_kconfig(__doc__) # See allnoconfig.py kconf.warn = False diff --git a/guiconfig.py b/guiconfig.py index 050789a..20ecfa1 100755 --- a/guiconfig.py +++ b/guiconfig.py @@ -95,7 +95,7 @@ an item will jump to it. Item values can be toggled directly within the dialog.\ def _main(): - menuconfig(standard_kconfig()) + menuconfig(standard_kconfig(__doc__)) # Global variables used below: diff --git a/kconfiglib.py b/kconfiglib.py index dacf5eb..237ecd1 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -6057,21 +6057,35 @@ def unescape(s): _unescape_sub = re.compile(r"\\(.)").sub -def standard_kconfig(): +def standard_kconfig(description=None): """ - 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. + Argument parsing helper for tools that take a single optional Kconfig file + argument (default: Kconfig). Uses argparse internally. - 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. + Exits with sys.exit() (which raises SystemExit) on errors. + + description (default: None): + The 'description' passed to argparse.ArgumentParser(). + argparse.RawDescriptionHelpFormatter is used, so formatting is preserved. """ - if len(sys.argv) > 2: - sys.exit("usage: {} [Kconfig]".format(sys.argv[0])) + import argparse + + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description=description) + + parser.add_argument( + "kconfig", + metavar="KCONFIG", + default="Kconfig", + nargs="?", + help="Kconfig file (default: Kconfig)") + + args = parser.parse_args() - # Only show backtraces for unexpected exceptions + # Suppress backtraces for expected exceptions try: - return Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1]) + return Kconfig(args.kconfig) except (EnvironmentError, KconfigError) as e: # Some long exception messages have extra newlines for better # formatting when reported as an unhandled exception. Strip them here. diff --git a/listnewconfig.py b/listnewconfig.py index 59de141..435819b 100755 --- a/listnewconfig.py +++ b/listnewconfig.py @@ -17,7 +17,7 @@ from kconfiglib import standard_kconfig, BOOL, TRISTATE, INT, HEX, STRING, \ def main(): - kconf = standard_kconfig() + kconf = standard_kconfig(__doc__) # Make it possible to filter this message out sys.stderr.write(kconf.load_config() + "\n") diff --git a/menuconfig.py b/menuconfig.py index 56e1a67..1f2e9fa 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -647,7 +647,7 @@ def _style_attr(fg_color, bg_color, attribs, color_attribs={}): def _main(): - menuconfig(standard_kconfig()) + menuconfig(standard_kconfig(__doc__)) def menuconfig(kconf): diff --git a/oldconfig.py b/oldconfig.py index 042ab44..ae9bf6d 100755 --- a/oldconfig.py +++ b/oldconfig.py @@ -44,7 +44,7 @@ def _main(): # visible symbols. global conf_changed - kconf = standard_kconfig() + kconf = standard_kconfig(__doc__) print(kconf.load_config()) while True: diff --git a/olddefconfig.py b/olddefconfig.py index a59a7d4..a4efd9a 100755 --- a/olddefconfig.py +++ b/olddefconfig.py @@ -19,7 +19,7 @@ import kconfiglib def main(): - kconf = kconfiglib.standard_kconfig() + kconf = kconfiglib.standard_kconfig(__doc__) print(kconf.load_config()) print(kconf.write_config()) |
