~landscape/charms/trusty/ntpmaster/trunk

« back to all changes in this revision

Viewing changes to hooks/utils.py

  • Committer: James Page
  • Date: 2013-08-29 13:19:15 UTC
  • mfrom: (1.1.55 ntpmaster)
  • Revision ID: james.page@canonical.com-20130829131915-gfu6zoqy5yj46c6s
Python rewrite from melmoth

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from charmhelpers.core.host import (
 
2
    apt_install,
 
3
    filter_installed_packages
 
4
)
 
5
 
 
6
 
 
7
TEMPLATES_DIR = 'templates'
 
8
 
 
9
try:
 
10
    import jinja2
 
11
except ImportError:
 
12
    apt_install(filter_installed_packages(['python-jinja2']),
 
13
                fatal=True)
 
14
    import jinja2
 
15
 
 
16
 
 
17
def render_template(template_name, context, template_dir=TEMPLATES_DIR):
 
18
    templates = jinja2.Environment(
 
19
        loader=jinja2.FileSystemLoader(template_dir))
 
20
    template = templates.get_template(template_name)
 
21
    return template.render(context)