~charmers/charms/trusty/ntpmaster/trunk

« back to all changes in this revision

Viewing changes to hooks/utils.py

  • Committer: Stuart Bishop
  • Date: 2016-06-20 07:44:34 UTC
  • mfrom: (16.1.1 ntpmaster)
  • Revision ID: stuart.bishop@canonical.com-20160620074434-ayj03v48zi803mr8
[paulgear, r=stub] Fix trusty deploys by using jinja helpers that work with Python3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from charmhelpers.fetch 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)