parent
39d32d1b49
commit
1227bc7d00
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2020 Simon Quigley <tsimonq2@lubuntu.me>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from jinja2 import Template
|
||||
from os import path
|
||||
|
||||
|
||||
def jinja2_template(src, dest, **kwargs):
|
||||
"""Wrapper for working with Jinja templates
|
||||
|
||||
src is the Jinja2 template to use, dest is where the rendered file needs
|
||||
to go, and any other keywords are passed directly to Template.render()
|
||||
"""
|
||||
|
||||
# Open the template file as a Jinja2 Template
|
||||
with open(src) as templatef:
|
||||
template = ""
|
||||
for text in templatef.readlines():
|
||||
template += text
|
||||
template = Template(template)
|
||||
|
||||
# Render the template
|
||||
template = template.render(**kwargs)
|
||||
|
||||
# Write the template to the dest
|
||||
with open(dest, "w+") as f:
|
||||
f.write(template)
|
||||
|
||||
return True
|
Loading…
Reference in new issue