1#!/usr/bin/env python 2import sdbusplus 3import mako.lookup 4import argparse 5import sys 6import os 7 8 9def main(): 10 module_path = os.path.dirname(sdbusplus.__file__) 11 12 valid_types = {'interface': sdbusplus.Interface, 13 'error': sdbusplus.Error} 14 valid_processes = {'markdown': "markdown", 15 'server-header': "server_header", 16 'server-cpp': "server_cpp", 17 'exception-header': "exception_header"} 18 19 parser = argparse.ArgumentParser(description='Process sdbus++ YAML files.') 20 21 parser.add_argument('-r', '--rootdir', dest='rootdir', default='example', 22 type=str, help='Location of files to process.') 23 parser.add_argument('-t', '--templatedir', dest='templatedir', 24 default=os.path.join(module_path, 'templates'), 25 type=str, help='Location of templates files.') 26 parser.add_argument('typeName', metavar='TYPE', type=str, 27 choices=valid_types.keys(), help='Type to operate on.') 28 parser.add_argument('process', metavar='PROCESS', type=str, 29 choices=valid_processes.keys(), 30 help='Process to apply.') 31 parser.add_argument('item', metavar='ITEM', type=str, 32 help='Item to process.') 33 34 args = parser.parse_args() 35 36 if sys.version_info < (3, 0): 37 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir], 38 disable_unicode=True) 39 else: 40 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir]) 41 42 instance = valid_types[args.typeName].load(args.item, args.rootdir) 43 function = getattr(instance, valid_processes[args.process]) 44 print(function(lookup)) 45 46if __name__ == '__main__': 47 main() 48