Pre-release charm-helpers sync

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

Change-Id: Ib5307473c7cba65c816bed923c1ed82e2d988f47
This commit is contained in:
David Ames 2016-07-15 10:17:41 -07:00
parent 8e6381d958
commit 017f641a50
2 changed files with 10 additions and 5 deletions

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
from charmhelpers.core import host from charmhelpers.core import host
from charmhelpers.core import hookenv 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 The rendered template will be written to the file as well as being returned
as a string. as a string.
Note: Using this requires python-jinja2; if it is not installed, calling Note: Using this requires python-jinja2 or python3-jinja2; if it is not
this will attempt to use charmhelpers.fetch.apt_install to install it. installed, calling this will attempt to use charmhelpers.fetch.apt_install
to install it.
""" """
try: try:
from jinja2 import FileSystemLoader, Environment, exceptions from jinja2 import FileSystemLoader, Environment, exceptions
@ -51,7 +53,10 @@ def render(source, target, context, owner='root', group='root',
'charmhelpers.fetch to install it', 'charmhelpers.fetch to install it',
level=hookenv.ERROR) level=hookenv.ERROR)
raise 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 from jinja2 import FileSystemLoader, Environment, exceptions
if template_loader: if template_loader:

View File

@ -178,14 +178,14 @@ def filter_installed_packages(packages):
return _pkgs return _pkgs
def apt_cache(in_memory=True): def apt_cache(in_memory=True, progress=None):
"""Build and return an apt cache""" """Build and return an apt cache"""
from apt import apt_pkg from apt import apt_pkg
apt_pkg.init() apt_pkg.init()
if in_memory: if in_memory:
apt_pkg.config.set("Dir::Cache::pkgcache", "") apt_pkg.config.set("Dir::Cache::pkgcache", "")
apt_pkg.config.set("Dir::Cache::srcpkgcache", "") apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
return apt_pkg.Cache() return apt_pkg.Cache(progress)
def apt_install(packages, options=None, fatal=False): def apt_install(packages, options=None, fatal=False):