1991bb769SMatt Spinler#!/usr/bin/env python3 25650b399SDeepak Kodihalli 35650b399SDeepak Kodihalliimport argparse 4*d27675d7SPatrick Williamsimport os 5*d27675d7SPatrick Williams 6*d27675d7SPatrick Williamsfrom mako.template import Template 7*d27675d7SPatrick Williams 8*d27675d7SPatrick Williamsimport yaml 95650b399SDeepak Kodihalli 105650b399SDeepak Kodihalli 115650b399SDeepak Kodihallidef main(): 12e6555f5bSPatrick Williams parser = argparse.ArgumentParser(description="Callout code generator") 135650b399SDeepak Kodihalli 145650b399SDeepak Kodihalli parser.add_argument( 15e6555f5bSPatrick Williams "-i", 16e6555f5bSPatrick Williams "--callouts_yaml", 17e6555f5bSPatrick Williams dest="callouts_yaml", 18e6555f5bSPatrick Williams default=os.path.join(script_dir, "callouts-example.yaml"), 19e6555f5bSPatrick Williams help="input callouts yaml", 20e6555f5bSPatrick Williams ) 21c040d392SPatrick Williams parser.add_argument( 22e6555f5bSPatrick Williams "-o", 23e6555f5bSPatrick Williams "--output", 24e6555f5bSPatrick Williams dest="output", 25e6555f5bSPatrick Williams default="callouts-gen.hpp", 26e6555f5bSPatrick Williams help="output file name (default: callouts-gen.hpp)", 27e6555f5bSPatrick Williams ) 28c040d392SPatrick Williams 295650b399SDeepak Kodihalli args = parser.parse_args() 305650b399SDeepak Kodihalli 31e6555f5bSPatrick Williams with open(args.callouts_yaml, "r") as fd: 325650b399SDeepak Kodihalli calloutsMap = yaml.safe_load(fd) 335650b399SDeepak Kodihalli 345650b399SDeepak Kodihalli # Render the mako template 35e6555f5bSPatrick Williams template = os.path.join(script_dir, "callouts-gen.mako.hpp") 365650b399SDeepak Kodihalli t = Template(filename=template) 37e6555f5bSPatrick Williams with open(args.output, "w") as fd: 38e6555f5bSPatrick Williams fd.write(t.render(calloutsMap=calloutsMap)) 395650b399SDeepak Kodihalli 405650b399SDeepak Kodihalli 41e6555f5bSPatrick Williamsif __name__ == "__main__": 425650b399SDeepak Kodihalli script_dir = os.path.dirname(os.path.realpath(__file__)) 435650b399SDeepak Kodihalli main() 44