~junaidali/charms/trusty/plumgrid-director/pg-restart

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/templating/jinja.py

  • Committer: Junaid Ali
  • Date: 2016-05-01 02:16:59 UTC
  • Revision ID: junaidali@plumgrid.com-20160501021659-niy7zqw0iy1celyy
update sleep time in restart_pg, changes for make sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2014-2015 Canonical Limited.
2
 
#
3
 
# This file is part of charm-helpers.
4
 
#
5
 
# charm-helpers is free software: you can redistribute it and/or modify
6
 
# it under the terms of the GNU Lesser General Public License version 3 as
7
 
# published by the Free Software Foundation.
8
 
#
9
 
# charm-helpers is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU Lesser General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU Lesser General Public License
15
 
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
"""
18
 
Templating using the python-jinja2 package.
19
 
"""
20
 
import six
21
 
from charmhelpers.fetch import apt_install, apt_update
22
 
try:
23
 
    import jinja2
24
 
except ImportError:
25
 
    apt_update(fatal=True)
26
 
    if six.PY3:
27
 
        apt_install(["python3-jinja2"], fatal=True)
28
 
    else:
29
 
        apt_install(["python-jinja2"], fatal=True)
30
 
    import jinja2
31
 
 
32
 
 
33
 
DEFAULT_TEMPLATES_DIR = 'templates'
34
 
 
35
 
 
36
 
def render(template_name, context, template_dir=DEFAULT_TEMPLATES_DIR):
37
 
    templates = jinja2.Environment(
38
 
        loader=jinja2.FileSystemLoader(template_dir))
39
 
    template = templates.get_template(template_name)
40
 
    return template.render(context)