summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-05-28 00:18:06 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-05-28 00:41:35 +0200
commitb95477a82d0a5bc4218aa00c8a76edc3c95d8d4f (patch)
tree93df71ffbcc86b763bba9c8a2f2964f4b6300afa /examples
parentfc73c461f1a8acf3e09670e8f9429c7ef9d0b71f (diff)
Simplify allyesconfig.py example with Kconfig.choices
Could do something similar to allnoconfig.py for the packaged version.
Diffstat (limited to 'examples')
-rw-r--r--examples/allyesconfig.py37
1 files changed, 8 insertions, 29 deletions
diff --git a/examples/allyesconfig.py b/examples/allyesconfig.py
index 0f15b1a..e27374e 100644
--- a/examples/allyesconfig.py
+++ b/examples/allyesconfig.py
@@ -32,49 +32,26 @@
from kconfiglib import Kconfig, Choice
import sys
-def all_choices(node):
- """
- Returns all choices in the menu tree rooted at 'node'. See the
- Kconfig.write_config() implementation in kconfiglib.py for an example of
- how the tree can be walked iteratively instead.
-
- (I was thinking of making a list of choices available directly in the API,
- but I'm not sure it will always be needed internally, and I'm trying to
- spam the API with less seldomly-used stuff compared to Kconfiglib 1.)
- """
- res = []
-
- while node:
- if isinstance(node.item, Choice):
- res.append(node.item)
-
- if node.list:
- res.extend(all_choices(node.list))
-
- node = node.next
-
- return res
-
kconf = Kconfig(sys.argv[1])
-non_choice_syms = [sym for sym in kconf.defined_syms if not sym.choice]
-choices = all_choices(kconf.top_node) # All choices in the configuration
-
while True:
changed = False
- for sym in non_choice_syms:
+ for sym in kconf.defined_syms:
+ # Choices are handled separately below
+ if sym.choice:
+ continue
+
# Set the symbol to the highest assignable value, unless it already has
# that value. sym.assignable[-1] gives the last element in assignable.
if sym.assignable and sym.tri_value < sym.assignable[-1]:
sym.set_value(sym.assignable[-1])
changed = True
- for choice in choices:
+ for choice in kconf.choices:
# Same logic as above for choices
if choice.assignable and choice.tri_value < choice.assignable[-1]:
choice.set_value(choice.assignable[-1])
- changed = True
# For y-mode choices, we just let the choice get its default
# selection. For m-mode choices, we set all choice symbols to m.
@@ -82,6 +59,8 @@ while True:
for sym in choice.syms:
sym.set_value(1)
+ changed = True
+
# Do multiple passes until we longer manage to raise any symbols or
# choices, like in allnoconfig.py
if not changed: