Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from __future__ import with_statement
from fabric.api import local, settings, abort, run, cd, env
from fabric.contrib.console import confirm
from fabric.contrib.files import exists, contains
# We reuse config from $HOME/.ssh/config
# Try
# fab --hosts=alwaysdata -f deploy_python
# or to set a specific version
# fab --hosts=alwaysdata -f deploy_python:version=2.7.5
# alwaysdata is an alias from $HOME/.ssh/config
# We declare we want to use parameters for SSH within Fabric
env.use_ssh_config = True
def deploy_python(version='2.7.8'):
directory_number = version.split('.')[0] + version.split('.')[1]
home = run("echo $HOME")
with cd(home):
run('mkdir -p python/src')
with cd('python/src'):
run('tar xvzf Python-{}.tgz'.format(version))
if (not exists(home + '/python/python{}'.format(directory_number))):
run('mkdir ' + home + '/python/python{}'.format(directory_number))
with cd(home + '/python/src/Python-{}'.format(version)):
run('./configure --prefix={}/python/python{}'.format(home, directory_number))
run('make install')
if (not contains('{}/.bash_profile'.format(home), 'python/python')):
run ('echo "export PATH=$HOME/python/python{}/bin:$PATH" >> ~/.bash_profile'.format(directory_number))
run('source ~/.bash_profile')
run('which python')
def deploy_setuptools_and_pip():
home = run("echo $HOME")
if (exists(home + '/python/src')):
with cd(home + '/python/src'):
run('wget --no-check-certificate')
run('tar xvfz setuptools-7.0.tar.gz')
with cd('setuptools-7.0'):
run('python install')
run('easy_install pip')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment