Pre-release charm-helpers sync

To begin release testing get each charm up to date with lp:charm-helpers

Change-Id: Ib14ceb4ec61c7b1a31f9b46b4406cd560e4a8857
This commit is contained in:
David Ames 2016-07-15 10:29:50 -07:00
parent 3c17fd5ba1
commit 8020a96700
2 changed files with 10 additions and 5 deletions

View File

@ -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:

View File

@ -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):