summaryrefslogtreecommitdiff
path: root/examples
AgeCommit message (Collapse)Author
2020-01-24Use 'python3' instead of 'python' in hashbangsUlf Magnusson
It's not obligatory for distributions to have a 'python' binary these days, but 'python3' is likely to be available: https://www.python.org/dev/peps/pep-0394/#for-python-runtime-distributors. Change all hashbangs to point to 'python3'. This will break running $ ./script.py on *nix systems that don't have a 'python3' executable. Changing it to $ python script.py is pretty painless at least. This change won't break Python 2 when installing via 'pip', because entry_points creates bounce scripts with their own hashbangs. The major version will be increased, in case someone looks at the major version but doesn't install via 'pip'. Fixes: #89
2019-12-14Add Kconfig.__init__() helper flag for suppressing tracebacksUlf Magnusson
Tools that don't use standard_kconfig() currently generate spammy tracebacks for e.g. syntax errors. Add a suppress_traceback flag to Kconfig.__init__() for catching "expected" exceptions and printing them to stderr and exiting with status 1. Use it to make all tools consistently hide tracebacks.
2019-10-29Add public helpers for generating "<name> (defined at ...)" stringsUlf Magnusson
Have Symbol/Choice.name_and_loc return strings like "MY_SYM (defined at foo:1, bar:2)" "<choice> (defined at foo:4)" I've added a function like that in at least four different scripts now, so that's probably a sign that it's a worthwhile helper. Clean up the tests/Klocation tests a bit while adding tests.
2019-07-02Catch EnvironmentError instead of OSError/IOErrorUlf Magnusson
menuconfig.py tended to crash on I/O errors on Python 2, due to forgetting to update some 'except OSError's. Catch EnvironmentError instead. EnvironmentError is a common base class of IOError and OSError on Python 2, and an alias for OSError on Python 3. Use it elsewhere too, as it might help catch obscure I/O errors on Python 2.
2019-06-07dumpvars: Make the output format copy-pasteableUlf Magnusson
Have it write assignments on a single line that can be copy-pasted before a command.
2019-06-03Improve warning control API (with backwards compatibility)Ulf Magnusson
A wart of the warning control API (enable/disable_*_warnings()) is that the current warning settings can't be queried. Querying warning settings is useful in functions that want to temporarily enable/disable some warning and then put things back to how they were. kconfiglib.load_allconfig() ran into this, for example. Make the internal warning control variables public (improve the naming at the same time), and encourage just setting them directly. Keep the old API for backwards compatibility. Also remove _warn_redun_assign() and _warn_override(). They're trivial and were called in a single place.
2019-06-03Have load_config() and write_(min_)config() return messagesUlf Magnusson
Hardcoding load_config() and write_(min_)config() to write any message to stdout is awkward, because it means that the message can't be easily reused when stdout is the wrong place to write it to (e.g. in menuconfig/guiconfig). This gets extra bad now that there's also the "No change to ..." message. Modify load_config() and write_(min_)config() to return the message as a string instead, and have them always return a message, instead of just when 'filename' is None and verbose=True. This makes things flexible and straightforward. Use the new behavior in menuconfig.py and guiconfig.py. They now show "No change to ..." when saving a file doesn't modify it. Tools that want to write messages to stdout should now do print(kconf.load_config()) / print(kconf.write_config()). There's no clean way to preserve perfect backwards compatibility here, but keep accepting the 'verbose' argument and print a deprecation warning if a value is ever passed for it. That way, scripts will keep running, though possibly with less output on stdout. This changes the meaning of the load_config() return value as well, though I suspect it was only ever used by the menuconfig/guiconfig interfaces. The new behavior applies for kconfiglib.VERSION >= (12, 0, 0).
2019-05-25Strip direct deps. from property conditions in Symbol/Choice/MenuNode.__str__()Ulf Magnusson
Commit e81a77b ("Consistently put direct deps. last when propagating") makes the position of the direct deps. in property conditions predictable after dependency propagation, making it easy to strip them as needed. Use this to implement MenuNode.orig_{prompt,defaults,selects,implies,ranges}, which work like the non-orig_* versions but omit the direct deps. Use those in turn to omit the direct deps in Symbol/Choice.__str__(). The direct deps. (with propagated parent deps.) can still be seen after 'depends on ...', so there is no loss of information. This unclutters Kconfig definitions shown in menuconfig/guiconfig and in any generated documentation. The old output also had duplicated dependencies, though it doesn't matter for evaluation. Before: config A bool prompt "A" if DEP default y if FOO && DEP depends on DEP After: config A bool prompt "A" default y if FOO depends on DEP
2019-05-19String repetition consistency nitUlf Magnusson
2019-03-06Use a consistent style in examplesUlf Magnusson
Also remove some unused imports.
2018-12-08Make {load,write}_config(filename=None) implement the standard behaviorUlf Magnusson
Make the previously obligatory 'filename' argument to load_config() and write_config() default to None, and have that implement the behavior you'd usually want: read/write either KCONFIG_CONFIG or ".config" if unset, and read the 'option defconfig_list' configuration file if KCONFIG_CONFIG/".config" doesn't exist. For load_config(), filename=None also allows the configuration file to be missing without raising an error. load_config() returns True if a local configuration file was loaded, which is useful to check in the menuconfig (if no local configuration file exists, we always want to prompt for saving the configuration when exiting). Also add a 'verbose' argument (default True) to load_config() and read_config() that makes them print which files were read/written in filename=None mode. Also generalize olddefconfig.py and oldconfig.py to not require there to already be a local configuration file. This was a bit silly for olddefconfig.py in particular. Remove the examples/defconfig.py script. It's a duplicate of olddefconfig.py.
2018-11-21Link Zephyr's kconfig.py from merge_config.py exampleUlf Magnusson
Helps to have a fancier example too.
2018-11-17Add support for KCONFIG_ALLCONFIGUlf Magnusson
This allows some symbol values to be forced while running all{def,no,yes,mod}config.py. See Documentation/kbuild/kconfig.txt in the Linux kernel. Add a helper function load_allconfig() to Kconfiglib to avoid code duplication in the tools. Also add functions for enabling/disabling the warning that's generated when a symbol is assigned multiple times in a (set of) .config files and the values differ. It should be disabled when merging the KCONFIG_ALLCONFIG configuration file. Previously, only the warning generated when the assigned values are identical could be disabled. Disable all warnings related to assigning a symbol multiple times in examples/merge_config.py as well.
2018-09-28Fix comment formatting in help_grep.pyUlf Magnusson
Consistently indent with tabs, like in the actual output.
2018-09-27Use a consistent import style in the examplesUlf Magnusson
Do the PEP 8 ordering thingy with standard library imports first.
2018-09-27Simplify the defconfig and eval_expr examples a bitUlf Magnusson
Style nits.
2018-09-15Update some examples to use node_iter()Ulf Magnusson
Simplifies the code. Should promote new APIs. Also fix list_undefined.py for recent kernels. More environment variables are referenced now.
2018-09-08Clean up kernel Makefile patch and add new targetsUlf Magnusson
Add two new targets: - 'make kmenuconfig' runs the menuconfig interface - 'make dumpvarsconfig' lists all referenced environment variables together with their values (assuming they used the preprocessor syntax) Remove the 'kconfiglibtestconfig' target, which is no longer used. Also clean up the target definitions. The joys of ancient code.
2018-08-22Add a generic node iteratorUlf Magnusson
Suggested by Mitja Horvat (pinkfluid) in https://github.com/ulfalizer/Kconfiglib/pull/50. Kconfig.node_iter() iterates through all menu nodes in the menu tree in Kconfig order. This saves scripts the trouble of implementing their own tree walking code. Have node_iter() take a 'unique_syms' flag that can be enabled to only include symbols defined in multiple locations once. This is often what you want when generating output (and is used by write_config()). Order is still preserved. Piggyback a fix to a syntax error test comment. Parsing has been tightened up now.
2018-08-22Introduce Kconfig.unique_defined_syms and Kconfig.unique_choicesUlf Magnusson
These are the same as Kconfig.defined_syms and Kconfig.choices, except duplicates are removed. Kconfig order is still preserved. This is almost always what you want when iterating through symbols and choices, as it potentially saves work, avoids generating duplicates when writing output, and still preserves Kconfig order for readability. The old attributes will be kept for backwards compatibility (maybe there's some rare cases where they could be useful too). They're created internally anyway.
2018-06-22Simplify the find_symbol and list_undefined examplesUlf Magnusson
Much of the functionality is available in Kconfiglib itself now. Use the new APIs to implement the examples in a much simpler way.
2018-06-11Add a function for getting all items in an expressionUlf Magnusson
Handy e.g. when searching.
2018-05-30allyesconfig: Prepare for packagingUlf Magnusson
Move to the root, simplify a bit, provide an entry point function (for setuptools's entry_points).
2018-05-28Simplify allyesconfig.py example with Kconfig.choicesUlf Magnusson
Could do something similar to allnoconfig.py for the packaged version.
2018-05-27allnoconfig: Move from examples/ to rootUlf Magnusson
Put to-be-packaged stuff in the root. Use allnoconfig_simpler.py, and rename allnoconfig.py to allnoconfig_walk.py and keep it as an example.
2018-05-27oldconfig: Move from examples/ to rootUlf Magnusson
All the packaged code will appear in the root.
2018-05-27oldconfig: Prepare for packagingUlf Magnusson
setuptools' 'entry_points' gives nice behavior on Windows. It requires that the module has an entry point function. Create one and move the command line argument handling to it. Piggyback KCONFIG_CONFIG support, and make the script executable (oversight).
2018-05-27oldconfig: Show help with '?' instead of '??'Ulf Magnusson
This matches the C tools. Hadn't noticed they had the same feature.
2018-05-27Simplify error exitsUlf Magnusson
Had missed sys.exit(msg).
2018-05-01Rename examples/menuconfig.py to menuconfig_example.pyUlf Magnusson
To avoid confusing it with the new terminal menuconfig implementation. Clean up the README a bit at the same time, removing some stuff that's less essential now (e.g. the menuconfig_example.py "screenshot").
2018-03-25merge_config.py: Clean up name_and_loc_str()Ulf Magnusson
- Rename to name_and_loc(), to be consistent with the kconfiglib.py version - Use a comment instead of a docstring. Shorten the description a bit too. - Piggyback a missing # in conf3 in the module docstring. Typo.
2018-03-18Add print_config_tree.py example script (#42)Ricardo F
Works like menuconfig.py, but just dumps the tree, with a specified .config file as base. Handy for diffing.
2018-02-25menuconfig.py: More style and comment nitsUlf Magnusson
- Use generator expression rather than list comprehension - Fix dubious English
2018-02-25menuconfig.py: Style and comment nitsUlf Magnusson
2018-02-23menuconfig.py: Remove unused STR_TO_TRI importUlf Magnusson
Piggyback a small note to clarify that symbols defined without a type are pretty obscure.
2018-02-09oldconfig.py style nitsUlf Magnusson
2018-02-09Simplify tri_value_str() in oldconfig.pyUlf Magnusson
2018-02-08oldconfig.py comment nitUlf Magnusson
2018-02-08oldconfig.py comment nitUlf Magnusson
2018-02-08Prompt for choices with new visible symbols in oldconfig.pyUlf Magnusson
It makes sense to prompt for a choice during oldconfig if it contains new visible symbols, even if there is already an old visible user selection.
2018-02-07Give symbol locations in merge_config.py warningsUlf Magnusson
Helpful for debugging. Piggyback some small fixes: - Don't imply that merge_config.py is an executable file or that it only runs under Python 3. Remove the hashbang line and fix the example in the overview. - Add some #'s to the overview .config files that had accidentally been left out. - Fix a questionable sentence in oldconfig.py's name_and_loc_str() docstring.
2018-02-07Allow "n"/"m"/"y" as aliases for 0/1/2 in set_value()Ulf Magnusson
More experience working with the API convinced me that it's worth it. Gets rid of ugly conversions in the menuconfig.py and oldconfig.py examples, and streamlines some things internally as well. Include two other small fixes as well: - Make warnings generated by Choice.set_value() match those generated by Symbol.set_value(). - Get rid of the input stripping in menuconfig.py. It's not like the interface is usable as-is anyway, and it just complicates the example.
2018-02-06Add help text display feature to oldconfig.pyUlf Magnusson
Typing '??' displays the help text of the current item.
2018-02-06Refactor do_oldconfig() slightlyUlf Magnusson
Not sure why anyone would want to oldconfig just a part of the configuration tree, especially as there might be dependencies pointing outside of it. Take a Kconfig object instead of a node.
2018-02-06Account for earlier symbols depending on later ones in oldconfig.pyUlf Magnusson
The oldnoconfig operation needs to be rerun if the value of any symbol changes, to catch cases where symbols depend on symbols defined after them. Otherwise the earlier symbols will just get their default value instead of being prompted for.
2018-02-06Consistently use 'kconf' instead of 'conf'Ulf Magnusson
The examples had some leftovers from Kconfiglib 1.
2018-02-06Add oldconfig.py example scriptUlf Magnusson
Implements the standard 'make oldconfig' functionality, prompting the user for the values of new symbols to update an old .config file. This came up in https://github.com/zephyrproject-rtos/zephyr/issues/5426.
2018-02-03Add example that finds references to undefined symbolsUlf Magnusson
Does a global search over all architectures in the kernel, which should avoid false positives. Referencing an undefined symbol in a particular architecture can be fine in a Kconfig file that's shared by multiple architectures, but if the symbol isn't defined by any architecture, it's likely to be an error (or a potential cleanup).
2017-12-30Add merge_config.py exampleUlf Magnusson
Functions similarly to scripts/kconfig/merge_config.sh from the kernel. Came up in https://github.com/zephyrproject-rtos/zephyr/pull/5417.
2017-11-27eval_expr.py: Fix missing argument error messageUlf Magnusson
Copy-paste error. Piggyback error message consistency nit for help_grep.py.