1import argparse 2import os 3 4import mako.lookup 5 6import sdbusplus 7 8 9def main(): 10 module_path = os.path.dirname(sdbusplus.__file__) 11 12 valid_types = { 13 "error": sdbusplus.Error, 14 "event": sdbusplus.Event, 15 "interface": sdbusplus.Interface, 16 } 17 valid_processes = { 18 "aserver-header": "async_server_header", 19 "client-header": "client_header", 20 "common-header": "common_header", 21 "exception-cpp": "exception_cpp", 22 "exception-header": "exception_header", 23 "exception-registry": "exception_registry", 24 "markdown": "markdown", 25 "server-cpp": "server_cpp", 26 "server-header": "server_header", 27 } 28 29 parser = argparse.ArgumentParser(description="Process sdbus++ YAML files.") 30 31 parser.add_argument( 32 "-r", 33 "--rootdir", 34 dest="rootdir", 35 default=".", 36 type=str, 37 help="Location of files to process.", 38 ) 39 parser.add_argument( 40 "-t", 41 "--templatedir", 42 dest="templatedir", 43 default=os.path.join(module_path, "templates"), 44 type=str, 45 help="Location of templates files.", 46 ) 47 parser.add_argument( 48 "-s", 49 "--schemadir", 50 dest="schemadir", 51 default=os.path.join(module_path, "schemas"), 52 type=str, 53 help="Location of schema files.", 54 ) 55 parser.add_argument( 56 "typeName", 57 metavar="TYPE", 58 type=str, 59 choices=valid_types.keys(), 60 help="Type to operate on.", 61 ) 62 parser.add_argument( 63 "process", 64 metavar="PROCESS", 65 type=str, 66 choices=valid_processes.keys(), 67 help="Process to apply.", 68 ) 69 parser.add_argument( 70 "item", 71 metavar="ITEM", 72 type=str, 73 help="Item to process.", 74 ) 75 76 args = parser.parse_args() 77 78 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir]) 79 80 instance = valid_types[args.typeName].load( 81 args.item, args.rootdir, args.schemadir 82 ) 83 function = getattr(instance, valid_processes[args.process]) 84 print(function(lookup)) 85