summaryrefslogtreecommitdiff
path: root/cloudinit/templater.py
blob: 5a3563a2199e1f2fe30ea745c6013664f99666e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os

from Cheetah.Template import Template

from cloudinit import settings
from cloudinit import util


def render_to_file(template, outfile, searchList):
    fn = template
    (base, ext) = os.path.splitext(fn)
    if ext != ".tmpl":
        fn = "%s.tmpl" % (fn)
    fn = os.path.join(settings.TEMPLATE_DIR, fn)
    contents = Template(file=fn, searchList=[searchList]).respond()
    util.write_file(outfile, contents)


def render_string(template, searchList):
    return Template(template, searchList=[searchList]).respond()