1#!/usr/bin/env python3 2# pylint: disable=R0903 3# Copyright(c) 2025: Mauro Carvalho Chehab <[email protected]>. 4# SPDX-License-Identifier: GPL-2.0 5 6""" 7Parse ABI documentation and produce results from it. 8""" 9 10import argparse 11import logging 12import os 13import sys 14 15# Import Python modules 16 17LIB_DIR = "lib/abi" 18SRC_DIR = os.path.dirname(os.path.realpath(__file__)) 19 20sys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR)) 21 22from abi_parser import AbiParser # pylint: disable=C0413 23from helpers import ABI_DIR, DEBUG_HELP # pylint: disable=C0413 24 25# Command line classes 26 27 28REST_DESC = """ 29Produce output in ReST format. 30 31The output is done on two sections: 32 33- Symbols: show all parsed symbols in alphabetic order; 34- Files: cross reference the content of each file with the symbols on it. 35""" 36 37class AbiRest: 38 """Initialize an argparse subparser for rest output""" 39 40 def __init__(self, subparsers): 41 """Initialize argparse subparsers""" 42 43 parser = subparsers.add_parser("rest", 44 formatter_class=argparse.RawTextHelpFormatter, 45 description=REST_DESC) 46 47 parser.add_argument("--enable-lineno", action="store_true", 48 help="enable lineno") 49 parser.add_argument("--raw", action="store_true", 50 help="output text as contained in the ABI files. " 51 "It not used, output will contain dynamically" 52 " generated cross references when possible.") 53 parser.add_argument("--no-file", action="store_true", 54 help="Don't the files section") 55 parser.add_argument("--show-hints", help="Show-hints") 56 57 parser.set_defaults(func=self.run) 58 59 def run(self, args): 60 """Run subparser""" 61 62 parser = AbiParser(args.dir, debug=args.debug) 63 parser.parse_abi() 64 parser.check_issues() 65 parser.print_data(args.enable_lineno, args.raw, not args.no_file) 66 67 68class AbiValidate: 69 """Initialize an argparse subparser for ABI validation""" 70 71 def __init__(self, subparsers): 72 """Initialize argparse subparsers""" 73 74 parser = subparsers.add_parser("validate", 75 formatter_class=argparse.ArgumentDefaultsHelpFormatter, 76 description="list events") 77 78 parser.set_defaults(func=self.run) 79 80 def run(self, args): 81 """Run subparser""" 82 83 parser = AbiParser(args.dir, debug=args.debug) 84 parser.parse_abi() 85 parser.check_issues() 86 87 88def main(): 89 """Main program""" 90 91 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) 92 93 parser.add_argument("-d", "--debug", type=int, default=0, help="debug level") 94 parser.add_argument("-D", "--dir", default=ABI_DIR, help=DEBUG_HELP) 95 96 subparsers = parser.add_subparsers() 97 98 AbiRest(subparsers) 99 AbiValidate(subparsers) 100 101 args = parser.parse_args() 102 103 if args.debug: 104 level = logging.DEBUG 105 else: 106 level = logging.INFO 107 108 logging.basicConfig(level=level, format="[%(levelname)s] %(message)s") 109 110 if "func" in args: 111 args.func(args) 112 else: 113 sys.exit(f"Please specify a valid command for {sys.argv[0]}") 114 115 116# Call main method 117if __name__ == "__main__": 118 main() 119