import os

from fabric.api import cd, env, run
from fabric.operations import sudo

env.proj_root = '/var/webapps/betafarm/'
git_repo = 'https://github.com/mozilla/betafarm.git'


def run_manage_cmd(cmd):
    """Run a manage.py command."""
    with cd(env.proj_root):
        run('python manage.py %s' % (cmd,))


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


def clone():
    """Create project directory and clone repository."""
    with cd(os.path.dirname(env.proj_root.rstrip('/'))):
        run('git clone --recursive %s' % (git_repo,))


def update():
    """Update project source."""
    with cd(env.proj_root):
        run('git pull origin master')


def migrate():
    """Run database migrations."""
    run_manage_cmd('migrate')


def compress():
    """Compress CSS / Javascript."""
    run_manage_cmd('compress_assets')


def deploy():
    update()
    compress()
    restart_apache()

@@ -664,24 +664,91 @@
  master')%0A%0A%0A
+def syncdb():%0A    %22%22%22Run syncdb.%22%22%22%0A    run_manage_cmd('syncdb')%0A%0A%0A
 def migrate(
@@ -793,33 +793,38 @@
     
-run_manage_cmd('migrate')
+# not implemented yet%0A    pass
 %0A%0A%0Ad
@@ -923,25 +923,292 @@
 def 
-deploy():%0A    upd
+switch(branchname):%0A    %22%22%22Switch branches%22%22%22%0A    with cd(env.proj_root):%0A        run('git checkout %25s' %25 (branchname,))%0A        run('git pull origin %25s' %25 (branchname,))%0A    syncdb()%0A    migrate()%0A    compress()%0A    restart_apache()%0A%0A%0Adef deploy():%0A    update()%0A    syncdb()%0A    migr
 ate(

Add support for switching branchs to fabfile