1*4b132aacSChuck Lever#!/usr/bin/env python3 2*4b132aacSChuck Lever# ex: set filetype=python: 3*4b132aacSChuck Lever 4*4b132aacSChuck Lever"""Generate source code boilerplate""" 5*4b132aacSChuck Lever 6*4b132aacSChuck Leverimport os.path 7*4b132aacSChuck Leverimport time 8*4b132aacSChuck Lever 9*4b132aacSChuck Leverfrom generators import Boilerplate 10*4b132aacSChuck Leverfrom generators import find_xdr_program_name, create_jinja2_environment 11*4b132aacSChuck Leverfrom xdr_ast import _RpcProgram, Specification, get_header_name 12*4b132aacSChuck Lever 13*4b132aacSChuck Lever 14*4b132aacSChuck Leverclass XdrSourceTopGenerator(Boilerplate): 15*4b132aacSChuck Lever """Generate source code boilerplate""" 16*4b132aacSChuck Lever 17*4b132aacSChuck Lever def __init__(self, language: str, peer: str): 18*4b132aacSChuck Lever """Initialize an instance of this class""" 19*4b132aacSChuck Lever self.environment = create_jinja2_environment(language, "source_top") 20*4b132aacSChuck Lever self.peer = peer 21*4b132aacSChuck Lever 22*4b132aacSChuck Lever def emit_source(self, filename: str, root: Specification) -> None: 23*4b132aacSChuck Lever """Emit the top source boilerplate""" 24*4b132aacSChuck Lever name = find_xdr_program_name(root) 25*4b132aacSChuck Lever template = self.environment.get_template(self.peer + ".j2") 26*4b132aacSChuck Lever print( 27*4b132aacSChuck Lever template.render( 28*4b132aacSChuck Lever program=name, 29*4b132aacSChuck Lever filename=filename, 30*4b132aacSChuck Lever mtime=time.ctime(os.path.getmtime(filename)), 31*4b132aacSChuck Lever ) 32*4b132aacSChuck Lever ) 33