diff --git a/hooks/charmhelpers/core/templating.py b/hooks/charmhelpers/core/templating.py index 0a7560ff..7b801a34 100644 --- a/hooks/charmhelpers/core/templating.py +++ b/hooks/charmhelpers/core/templating.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import sys from charmhelpers.core import host from charmhelpers.core import hookenv @@ -38,8 +39,9 @@ def render(source, target, context, owner='root', group='root', The rendered template will be written to the file as well as being returned as a string. - Note: Using this requires python-jinja2; if it is not installed, calling - this will attempt to use charmhelpers.fetch.apt_install to install it. + Note: Using this requires python-jinja2 or python3-jinja2; if it is not + installed, calling this will attempt to use charmhelpers.fetch.apt_install + to install it. """ try: from jinja2 import FileSystemLoader, Environment, exceptions @@ -51,7 +53,10 @@ def render(source, target, context, owner='root', group='root', 'charmhelpers.fetch to install it', level=hookenv.ERROR) raise - apt_install('python-jinja2', fatal=True) + if sys.version_info.major == 2: + apt_install('python-jinja2', fatal=True) + else: + apt_install('python3-jinja2', fatal=True) from jinja2 import FileSystemLoader, Environment, exceptions if template_loader: diff --git a/hooks/charmhelpers/fetch/__init__.py b/hooks/charmhelpers/fetch/__init__.py index 8f39f2fe..52eaf824 100644 --- a/hooks/charmhelpers/fetch/__init__.py +++ b/hooks/charmhelpers/fetch/__init__.py @@ -178,14 +178,14 @@ def filter_installed_packages(packages): return _pkgs -def apt_cache(in_memory=True): +def apt_cache(in_memory=True, progress=None): """Build and return an apt cache""" from apt import apt_pkg apt_pkg.init() if in_memory: apt_pkg.config.set("Dir::Cache::pkgcache", "") apt_pkg.config.set("Dir::Cache::srcpkgcache", "") - return apt_pkg.Cache() + return apt_pkg.Cache(progress) def apt_install(packages, options=None, fatal=False):