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