Catch template exceptions

This commit is contained in:
Martin Gracik 2010-10-29 14:41:23 +02:00
parent 1a5a636e24
commit 2fc71cc74e

View File

@ -19,10 +19,12 @@
# Red Hat Author(s): Martin Gracik <mgracik@redhat.com>
#
import sys
import shlex
from mako.template import Template
from mako.lookup import TemplateLookup
from mako.exceptions import RichTraceback
class LoraxTemplate(object):
@ -32,7 +34,16 @@ class LoraxTemplate(object):
# otherwise the file includes will not work properly
lookup = TemplateLookup(directories=["/"])
template = Template(filename=template_file, lookup=lookup)
try:
s = template.render(**variables)
except:
traceback = RichTraceback()
for (filename, lineno, function, line) in traceback.traceback:
print "File %s, line %s, in %s" % (filename, lineno, function)
print line
sys.exit(2)
# split, strip and remove empty lines
lines = s.splitlines()