diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/allnoconfig_walk.py | 2 | ||||
| -rw-r--r-- | examples/defconfig_oldconfig.py | 2 | ||||
| -rwxr-xr-x[-rw-r--r--] | examples/menuconfig_example.py | 24 | ||||
| -rwxr-xr-x[-rw-r--r--] | examples/merge_config.py | 28 |
4 files changed, 32 insertions, 24 deletions
diff --git a/examples/allnoconfig_walk.py b/examples/allnoconfig_walk.py index 24b2828..5a8cc23 100644 --- a/examples/allnoconfig_walk.py +++ b/examples/allnoconfig_walk.py @@ -63,4 +63,4 @@ while True: if not changed: break -kconf.write_config() +print(kconf.write_config()) diff --git a/examples/defconfig_oldconfig.py b/examples/defconfig_oldconfig.py index 98f97a0..68336c6 100644 --- a/examples/defconfig_oldconfig.py +++ b/examples/defconfig_oldconfig.py @@ -36,4 +36,4 @@ for s in kconf.unique_defined_syms: s.set_value(0) # Write the final configuration -kconf.write_config() +print(kconf.write_config()) diff --git a/examples/menuconfig_example.py b/examples/menuconfig_example.py index 4e2560d..b265e69 100644..100755 --- a/examples/menuconfig_example.py +++ b/examples/menuconfig_example.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # Implements a simple configuration interface on top of Kconfiglib to # demonstrate concepts for building a menuconfig-like. Emulates how the # standard menuconfig prints menu entries. @@ -117,6 +119,7 @@ # # Enter a symbol/choice name, "load_config", or "write_config" (or press CTRL+D to exit): ^D +from __future__ import print_function import readline import sys @@ -300,27 +303,22 @@ if __name__ == "__main__": if cmd == "load_config": config_filename = input(".config file to load: ") - try: - kconf.load_config(config_filename) + # Returns a message telling which file got loaded + print(kconf.load_config(config_filename)) except IOError as e: - # Print the (spammy) error from Kconfiglib itself - print(e.message + "\n") - else: - print("Configuration loaded from " + config_filename) + print(e, file=sys.stderr) print_menuconfig(kconf) continue if cmd == "write_config": config_filename = input("To this file: ") - try: - kconf.write_config(config_filename) + # Returns a message telling which file got saved + print(kconf.write_config(config_filename)) except IOError as e: - print(e.message) - else: - print("Configuration written to " + config_filename) + print(e, file=sys.stderr) continue @@ -340,5 +338,5 @@ if __name__ == "__main__": continue - print("No symbol/choice named '{}' in the configuration" - .format(cmd)) + print("No symbol/choice named '{}' in the configuration".format(cmd), + file=sys.stderr) diff --git a/examples/merge_config.py b/examples/merge_config.py index ec022d5..6f60375 100644..100755 --- a/examples/merge_config.py +++ b/examples/merge_config.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # This script functions similarly to scripts/kconfig/merge_config.sh from the # kernel tree, merging multiple configurations fragments to produce a complete # .config, with unspecified values filled in as for alldefconfig. @@ -37,7 +39,8 @@ # # conf3 contents: # -# # Ops... assigned twice +# # Assigned twice (would generate warning if 'warn_assign_override' was +# # True) # # CONFIG_FOO is not set # # # Ops... this symbol doesn't exist @@ -54,15 +57,20 @@ # Running: # # $ python(3) merge_config.py Kconfig merged conf1 conf2 conf3 conf4 -# conf3:2: warning: FOO (defined at Kconfig:1) set more than once. Old value: "y", new value: "n". -# conf3:5: warning: attempt to assign the value "y" to the undefined symbol OPS -# warning: QAZ (defined at Kconfig:10) was assigned the value "y" but got the value "n" -- check dependencies +# Merged configuration 'conf1' +# Merged configuration 'conf2' +# conf3:5: warning: attempt to assign the value 'y' to the undefined symbol OPS +# Merged configuration 'conf3' +# Merged configuration 'conf4' +# Configuration saved to 'merged' +# warning: QAZ (defined at Kconfig:10) was assigned the value 'y' but got the value 'n' -- check dependencies # $ cat merged # Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) # # CONFIG_FOO is not set # CONFIG_BAR=y # CONFIG_BAZ="baz string" +from __future__ import print_function import sys from kconfiglib import Kconfig, BOOL, TRISTATE, TRI_TO_STR @@ -86,12 +94,13 @@ kconf.enable_undef_warnings() kconf.disable_override_warnings() kconf.disable_redun_warnings() -# Create a merged configuration by loading the fragments with replace=False +# Create a merged configuration by loading the fragments with replace=False. +# load_config() and write_config() returns a message to print. for config in sys.argv[3:]: - kconf.load_config(config, replace=False) + print(kconf.load_config(config, replace=False)) # Write the merged configuration -kconf.write_config(sys.argv[2]) +print(kconf.write_config(sys.argv[2])) # Print warnings for symbols whose actual value doesn't match the assigned # value @@ -119,5 +128,6 @@ for sym in kconf.defined_syms: if user_value != sym.str_value: print("warning: {} was assigned the value '{}' but got the " - "value '{}' -- check dependencies" - .format(name_and_loc(sym), user_value, sym.str_value)) + "value '{}' -- check dependencies".format( + name_and_loc(sym), user_value, sym.str_value), + file=sys.stderr) |
