def push(): """ Deploy commit identified by ``set_commit`` previously. The release is not set live - the 'current' point is not amended - until ``activate`` is invoked. The latter is a fast operation whilst this is slow. """ commit = get_commit() zipfile, _ = create_archive(commit) zfname = os.path.split(zipfile)[-1] # based on whether the archive is on the remote system or not, push our # archive packages_dir = project_path('packages') target_file = project_path('packages', zfname) base_dir = project_path() if not exists(project_path('bin', 'activate')): with settings(warn_only=True): res = sudo("virtualenv {}".format(base_dir)) # TODO: install setuptools and virtualenv? or bootatrap, e.g. # http://eli.thegreenplace.net/2013/04/20/bootstrapping-virtualenv/ if not res.succeeded: if "virtualenv: command not found" in res: raise RuntimeError( "Virtualenv not installed on target server!") else: raise RuntimeError(res) sudo("chown -R {} {}".format(USER, base_dir)) if not exists(target_file): usudo("mkdir -p {}".format(packages_dir)) # can't pass a user to 'put' put(zipfile, target_file, use_sudo=True) sudo("chown -R {} {}".format(USER, target_file)) usudo("cd /; tar zxf {}".format(target_file)) if getattr(env, "install_requirements", True): if getattr(env, "pip_upgrade", False): upgrade_flag = "--upgrade" else: upgrade_flag = "" if getattr(env, "pip_quiet", False): quiet_flag = "--quiet" else: quiet_flag = "" with fab_prefix(activate_command()): usudo("pip install {} -r requirements.txt {}".format( upgrade_flag, quiet_flag))
def purge_local_package(package): """ Purge a pip installed package from a project virtualenv. """ with fab_prefix(activate_command()): usudo("pip uninstall --yes {}".format(package))