def process_to_tempfile(filepath: str, context: Dict[str, Any]) -> str:
"""
renders the template in ``filepath`` using ``context`` through Jinja2. The result
is saved into a temporary file, which will be garbage collected automatically when the
program exits.
:return: the full path of the temporary file containing the result
"""
outfd, ofname = tempfile.mkstemp()
with open(outfd, mode="w") as outf:
with open(filepath) as inf:
tplstr = inf.read()
tpl = jinja2.Template(tplstr)
outf.write(tpl.render(context))
import gopythongo.main
gopythongo.main.tempfiles.append(ofname)
return ofname
评论列表
文章目录