# coding: utf-8
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from six.moves import input
import os
import time

print()
print("Hey things have changed.")
print()
time.sleep(1)
print("We now do deploys from the commcarehq-ansible directory or the control machine.")
print()
time.sleep(2)
if 'y' == input('Do you want instructions for how to migrate? [y/N]'):
    print()
    ansible_repo = os.path.join(os.path.dirname(__file__), '..', 'commcarehq-ansible')
    if not os.path.isdir(os.path.join(ansible_repo, '.git')):
        print("""
    Set up commcarehq-ansible
    =========================

    Put the commcarehq-ansible repo alongside this one like so:

      cd ..
      git clone https://github.com/dimagi/commcarehq-ansible.git
      cd commcarehq-ansible

    Now make a virtualenv for ansible:

      mkvirtualenv ansible

""")
    else:
        print("✓ You already have the commcarehq-ansible repo alonside this one: {}"
              .format(os.path.realpath(ansible_repo)))
        print()
        time.sleep(1)
    print("""
    Make your ansible environment fab-ready
    =======================================

    Enter the commcarehq-ansible repo and make sure you have the latest

      cd ../commcarehq-ansible
      git pull

    enter the env

      workon ansible

    do the necessary pip installs

      pip install -r fab/requirements.txt

    and make sure the necessary files are in the right place

      ./control/check_install.sh

    Run a fab command!
    ==================

    Enter the fab directory of commcarehq-ansible

      cd commcarehq-ansible/fab

    Run your fab command

      fab production deploy


    Bonus: Run fab from any directory
    =================================

    You will always need to enter the ansible virtualenv to run fab from now on,
    but if you use the following alias, you can run it from anywhere.

      alias fab='fab -f ~/.commcare-cloud/repo/fab/fabfile.py'

    to make alias always available, add it to the profile file you use for your aliases,
    possibly one of the following:

      echo "alias fab='fab -f ~/.commcare-cloud/repo/fab/fabfile.py'" >> ~/.profile
      echo "alias fab='fab -f ~/.commcare-cloud/repo/fab/fabfile.py'" >> ~/.bash_profile
      echo "alias fab='fab -f ~/.commcare-cloud/repo/fab/fabfile.py'" >> ~/.bashrc

    Now from anywhere

      workon ansible
      fab production deploy
""")
exit(1)

@@ -454,16 +454,32 @@
 _repo = 
+os.path.abspath(
 os.path.
@@ -537,16 +537,17 @@
 nsible')
+)
 %0A    if 
@@ -601,16 +601,113 @@
 git')):%0A
+        if 'y' != input('Do you have a local commcarehq-ansible repository already? %5By/N%5D'):%0A    
         
@@ -1021,16 +1021,389 @@
 e%0A%0A%22%22%22)%0A
+        else:%0A            print(%22%22%22%0A    Link commcarehq-ansible repo%0A    ============================%0A%0A    Symlink your commcarehq-ansible repo so that it lives alongside this one:%0A%0A      ln -s %3Cpath/to/commcarehq-ansible%3E %7Bansible_repo%7D%0A%0A    When you have done that, run%0A%0A      fab%0A%0A    to see more instructions.%0A%22%22%22.format(ansible_repo=ansible_repo))%0A            exit(1)%0A
     else
@@ -1515,25 +1515,8 @@
 mat(
-os.path.realpath(
 ansi
@@ -1525,17 +1525,16 @@
 e_repo))
-)
 %0A       

add contingency for commcarehq-ansible repo at different location