From a15c5ded9cf95bf62e70e97bcab302b41002584d Mon Sep 17 00:00:00 2001 From: Will Woods Date: Mon, 9 May 2011 23:42:10 -0400 Subject: [PATCH] Add "directories=[]" param to LoraxTemplate --- src/pylorax/ltmpl.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 00e870db..a39aa76e 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -22,18 +22,19 @@ import sys import shlex -from mako.template import Template from mako.lookup import TemplateLookup from mako.exceptions import RichTraceback class LoraxTemplate(object): + def __init__(self, directories=["/usr/share/lorax"]): + # we have to add ["/"] to the template lookup directories or the + # file includes won't work properly for absolute paths + self.directories = ["/"] + directories def parse(self, template_file, variables): - # we have to set the template lookup directories to ["/"], - # otherwise the file includes will not work properly - lookup = TemplateLookup(directories=["/"]) - template = Template(filename=template_file, lookup=lookup) + lookup = TemplateLookup(directories=self.directories) + template = lookup.get_template(template_file) try: textbuf = template.render(**variables)