Sync charm-helpers

This commit is contained in:
Corey Bryant 2015-05-05 19:18:13 +00:00
parent 007ddd59c8
commit 6a13a3aa97
3 changed files with 27 additions and 4 deletions

View File

@ -53,9 +53,13 @@ from charmhelpers.contrib.network.ip import (
get_ipv6_addr get_ipv6_addr
) )
from charmhelpers.contrib.python.packages import (
pip_create_virtualenv,
pip_install,
)
from charmhelpers.core.host import lsb_release, mounts, umount from charmhelpers.core.host import lsb_release, mounts, umount
from charmhelpers.fetch import apt_install, apt_cache, install_remote from charmhelpers.fetch import apt_install, apt_cache, install_remote
from charmhelpers.contrib.python.packages import pip_install
from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk
from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device
@ -536,6 +540,8 @@ def git_clone_and_install(projects_yaml, core_project, depth=1):
if 'directory' in projects.keys(): if 'directory' in projects.keys():
parent_dir = projects['directory'] parent_dir = projects['directory']
pip_create_virtualenv(proxy=http_proxy)
for p in projects['repositories']: for p in projects['repositories']:
repo = p['repository'] repo = p['repository']
branch = p['branch'] branch = p['branch']

View File

@ -17,8 +17,11 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
import os
import subprocess
from charmhelpers.fetch import apt_install, apt_update from charmhelpers.fetch import apt_install, apt_update
from charmhelpers.core.hookenv import log from charmhelpers.core.hookenv import charm_dir, log
try: try:
from pip import main as pip_execute from pip import main as pip_execute
@ -94,3 +97,17 @@ def pip_list():
"""Returns the list of current python installed packages """Returns the list of current python installed packages
""" """
return pip_execute(["list"]) return pip_execute(["list"])
def pip_create_virtualenv(parent_dir=charm_dir(), proxy=None):
"""Create and activate an isolated Python environment (virtualenv)."""
if proxy:
pip_install('virtualenv', proxy=proxy)
else:
pip_install('virtualenv')
venv_dir = os.path.join(parent_dir, 'venv')
subprocess.check_call(['virtualenv', '--no-site-packages', venv_dir])
venv_activate = os.path.join(venv_dir, 'bin/activate')
subprocess.check_call(['.', venv_activate], shell=True)

View File

@ -50,9 +50,9 @@ class GitUrlFetchHandler(BaseFetchHandler):
raise UnhandledSource("Cannot handle {}".format(source)) raise UnhandledSource("Cannot handle {}".format(source))
if depth: if depth:
repo = Repo.clone_from(source, dest, branch=branch, depth=depth) Repo.clone_from(source, dest, branch=branch, depth=depth)
else: else:
repo = Repo.clone_from(source, dest, branch=branch) Repo.clone_from(source, dest, branch=branch)
def install(self, source, branch="master", dest=None, depth=None): def install(self, source, branch="master", dest=None, depth=None):
url_parts = self.parse_url(source) url_parts = self.parse_url(source)