"""Tasks that deal with deployment."""

from fabric.api import abort, hide, lcd, local, task

import heroku
from settings import PROJECT_ROOT
from utils import get_tag_names, is_working_directory_clean, msg, need_to_tag


@task
def prepare_to_deploy():
    """Prepare the project's working copy for deployment."""
    with lcd(PROJECT_ROOT), hide('commands'):
        if not is_working_directory_clean():
            abort("Working directory must be clean before deployment.")
        local('git pull')


@task
def tag_project(prefix):
    """Tag the project for the specified environment."""
    if prefix is None:
        abort('Tag prefix must be specified!')

    (last_tag_name, next_tag_name) = get_tag_names(prefix)

    print('Last tag: %s' % last_tag_name)
    print('Next tag: %s' % next_tag_name)

    if not need_to_tag("HEAD", last_tag_name):
        print("Current tag '%s' is the most recent version." % last_tag_name)
        return

    #with msg("Tagging project with '%s'" % next_tag_name):
    local('git tag -a -m "Tag latest for %s." %s' % (prefix, next_tag_name))


@task
def deploy_to_heroku():
    """Deploy the site to Heroku."""
    with lcd(PROJECT_ROOT):
        with heroku.maintenance(), hide('running'):
            local("git push heroku")
            local("heroku run python manage.py syncdb --noinput")
            # TODO: Integrate South to support database migration.
            #local("heroku run python manage.py migrate")

@@ -657,16 +657,66 @@
 ied!')%0A%0A
+    with lcd(PROJECT_ROOT), hide('commands'):%0A    
     (las
@@ -767,24 +767,28 @@
 refix)%0A%0A    
+   
+ 
 print('Last 
@@ -809,24 +809,28 @@
 t_tag_name)%0A
+    
     print('N
@@ -860,16 +860,20 @@
 _name)%0A%0A
+    
     if n
@@ -915,24 +915,28 @@
 e):%0A        
+ 
+   
 print(%22Curre
@@ -1001,16 +1001,20 @@
         
+    
 return%0A%0A
@@ -1017,17 +1017,20 @@
 rn%0A%0A    
-#
+    
 with msg
@@ -1072,24 +1072,32 @@
 _tag_name):%0A
+        
     local('g

Change into the project root before tagging the project.