Source

fabulator / src / fabulator / core / virtualenv.py

Full commit
"""
    virtualenv management functions

"""
import os

from fabric.api import run, sudo, cd
from fabric.contrib.files import exists

class VirtualEnv(object):
    """Virtualenv class"""
    
    def __init__(self, conf, env):
        self.conf = conf
        self.env = env
        self.dir = conf.get("dir")
        self.bin_dir = self.dir + os.sep + "bin"
        self.bin = conf.get("bin") or "virtualenv"
        self.requirements = conf.get("requirements", [])
        self.requirements_file = conf.get("requirements_file")
    
    def create_virtualenv(self, folder=None, pip=True):
        """creates the virtualenv"""
        run("%s %s" % (self.bin, self.dir))
        if pip:
            self.install_pip()
        
    def install_pip(self):
        """checks if pip exists or install it using easy_install"""
        if not exists("%s/pip" % self.bin_dir):
            run("%s/easy_install pip" % (self.bin_dir))

    def install_requirements(self, use_file=True):
        
        if self.requirements_file:
            run("%s/pip install -r %s" % (self.bin_dir, self.conf.get("requirements_file")))
        for requirement in self.requirements:
            run("%s/pip install %s" % (self.bin_dir, requirement))
        
    def update_requirements(self, use_file=True):
        if use_file:
            run("%s/pip install  -r %s --upgrade" % (self.bin_dir, self.conf.get("requirements-file")))
        else:
            for requirement in self.requirements:
                run("%s/pip install %s --upgrade" % (self.bin_dir, requirement))

    def remove_virtualenv(self):
        run("rm -Rf %s" % self.dir)