Last active
August 29, 2015 14:08
-
-
Save ThomasG77/0fc446643d2d8b3e0e05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_27_alwaysdata.py deploy_python | |
# or to set a specific version | |
# fab --hosts=alwaysdata -f deploy_python_27_alwaysdata.py 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('wget https://www.python.org/ftp/python/{0}/Python-{0}.tgz'.format(version)) | |
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') | |
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 https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz --no-check-certificate') | |
run('tar xvfz setuptools-7.0.tar.gz') | |
with cd('setuptools-7.0'): | |
run('python setup.py install') | |
run('easy_install pip') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment