lxc-network/lxc_net/xml_template.py

24 lines
657 B
Python
Raw Normal View History

2020-03-09 12:14:26 +01:00
""" Reads an XML template from a file """
import os
2020-03-09 13:00:10 +01:00
import jinja2
2020-03-09 12:14:26 +01:00
class XMLTemplate:
""" Reads and instanciates a template from a file """
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
2020-03-09 13:00:10 +01:00
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(base_path),
autoescape=jinja2.select_autoescape(
enabled_extensions=("xml"), default_for_string=True,
),
)
2020-03-09 12:14:26 +01:00
def __init__(self, path):
2020-03-09 13:00:10 +01:00
self.template = self.env.get_template(path)
2020-03-09 12:14:26 +01:00
def inst(self, *args, **kwargs):
""" instanciates the template """
2020-03-09 13:00:10 +01:00
return self.template.render(*args, **kwargs)