Source

snippets / maintanance / deploy / fabfile.py

The default branch has multiple heads

################################################################
# It uses fabfile to build and deploy
# Ref: http://thejeshgn.com/2012/02/02/deployment-php-python-app-using-mercurial-and-fabfile
# usage:
#        cd to the folder
#        $ fab hello    
#
#To deploy tagged version to test:
#        cd to the folder which has fab file
#        $fab test deploy:REPO_TAG_NAME
#
#To deploy latest version to test:
#        cd to the folder which has fab file
#        $fab test deploy:tip
#
#To deploy to prod:
#        cd to the folder which has fab file
#        $fab prod deploy:REPO_TAG_NAME
#
#

################################################################
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm

def hello():
    print("Welcome to web deployment.")
    
def test():
    env.user = 'user_name'
    env.hosts = ['100.100.100.100']
    env.password ='password'
    env.consumer_key ="test_xGxRxzXrxoxSxrxYxuxdxnxLxBxzQU00Q"

def prod():
    env.user = 'user_name'
    env.hosts = ['200.200.200.200']
    env.password ='password'
    env.consumer_key ="prod_xGxRxzXrxoxSxrxYxuxdxnxLxBxzQU00Q"

def update(version):  
    with cd('/home/user_home/public_html/tweet4blood.com'):  
        run('hg pull')      
        run('hg update -C '+version)      
    with cd('/home/user_home/public_html/tweet4blood.com/html/auth/'):
            consumer_key_defnition = "define('CONSUMER_KEY', '"+ +"');"                         
            run("sed -i 's/define('CONSUMER_KEY', 'xGxRxzXrxoxSxrxYxuxdxnxLxBxzQU00Q');/"+consumer_key_defnition+"/' config.php")

def apache_restart():  
    sudo('/etc/init.d/apache2 restart') 

def apache_stop():  
    sudo('/etc/init.d/apache2 stop') 

def apache_start():  
    sudo('/etc/init.d/apache2 start')
 
def apache_status():
    sudo('ps aux | egrep "(PID|apache2)"')

def deploy(version):
    update(version)