""" Overview ======== Kconfiglib is a Python 2/3 library for scripting and extracting information from Kconfig-based configuration systems. Features include the following: - Programmatic getting and setting of symbol values - Reading/writing of .config files - Inspection of symbol properties and expressions: printing a symbol (calling Symbol.__str__()) gives output which could be fed back into a Kconfig parser to redefine the symbol, and __str__() is implemented with only public APIs. A helpful __repr__() is implemented on all objects as well, also implemented with public APIs. - Expressions use a simple tuple-based format and can be processed manually if needed. - Menu tree inspection: The underlying menu tree is exposed, including submenus created implicitly from symbols depending on preceding symbols. This can be used e.g. to implement menuconfig-like functionality. - Runs under both Python 2 and 3. The code mostly uses basic Python features and has no third-party dependencies (the most advanced things used are @property and __slots__). - Robust and highly compatible with the standard Kconfig C tools: The test suite automatically compares output from Kconfiglib and the C tools (by diffing generated .config files) on the real kernel Kconfig and defconfig files, for all ARCHes. All tests are expected to pass. A set of selftests is also included. - Not horribly slow despite being a pure Python implementation: Parses the x86 Kconfigs in about a second on a Core i7 2600K (with a warm file cache). For long-running jobs, PyPy gives a big performance boost. - Internals that (mostly) mirror the C implementation while being simpler to understand. Using Kconfiglib on the Linux kernel with the Makefile targets ============================================================== For the Linux kernel, a handy interface is provided by the scripts/kconfig/Makefile patch, which adds the following targets: make iscriptconfig ------------------ This target gives an interactive Python prompt where the configuration for ARCH has been preloaded and is available in 'kconf'. To get a feel for the API, try evaluating and printing the symbols in kconf.defined_syms, and explore the menu tree starting at kconf.top_node by following 'next' and 'list' pointers. The item contained in the menu node is found in MenuNode.item, and all symbols and choices have a 'nodes' attribute which gives their menu nodes (usually only one). If you want to look up a symbol by name, use the kconf.syms dictionary. As usual, ARCH= can be passed to 'make' to select the arch. PYTHONCMD= selects the Python executable to use (default: "python"). Tip: IronPython (PYTHONCMD=ipython) is handy when figuring out the API, as it provides autocompletion for attributes. make scriptconfig SCRIPT=