Atlas - help_grep.py

Home / ext / kconfiglib / examples Lines: 2 | Size: 1639 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1# Does a case-insensitive search for a regular expression in the help texts of 2# symbols and choices and the prompts of menus and comments. Prints the 3# matching items together with their locations and the matching text. 4# 5# Usage: 6# 7# $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/help_grep.py SCRIPT_ARG=<regex> 8# 9# Shortened example output for SCRIPT_ARG=general: 10# 11# menu "General setup" 12# location: init/Kconfig:39 13# 14# config SYSVIPC 15# bool 16# prompt "System V IPC" 17# help 18# ... 19# exchange information. It is generally considered to be a good thing, 20# ... 21# 22# location: init/Kconfig:233 23# 24# config BSD_PROCESS_ACCT 25# bool 26# prompt "BSD Process Accounting" if MULTIUSER 27# help 28# ... 29# information. This is generally a good idea, so say Y. 30# 31# location: init/Kconfig:403 32# 33# ... 34 35 36import re 37import sys 38 39from kconfiglib import Kconfig, Symbol, Choice, MENU, COMMENT 40 41 42if len(sys.argv) < 3: 43 sys.exit("Pass the regex with SCRIPT_ARG=<regex>") 44 45search = re.compile(sys.argv[2], re.IGNORECASE).search 46 47for node in Kconfig(sys.argv[1]).node_iter(): 48 match = False 49 50 if isinstance(node.item, (Symbol, Choice)) and \ 51 node.help is not None and search(node.help): 52 print(node.item) 53 match = True 54 55 elif node.item == MENU and search(node.prompt[0]): 56 print('menu "{}"'.format(node.prompt[0])) 57 match = True 58 59 elif node.item == COMMENT and search(node.prompt[0]): 60 print('comment "{}"'.format(node.prompt[0])) 61 match = True 62 63 if match: 64 print("location: {}:{}\n".format(node.filename, node.linenr)) 65
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.