from datetime import datetime

from fabric.api import (
    cd,
    env,
    local,
    put,
    run,
    sudo,
    task
)


PRODUCTION_IP = '54.154.235.243'
PROJECT_DIRECTORY = '/home/ubuntu/ztm/'
BACKUP_DIRECTORY = '/home/ubuntu/backup/'
COMPOSE_FILE = 'compose-production.yml'


@task
def production():
    env.run = sudo
    env.hosts = [
        'ubuntu@' + PRODUCTION_IP + ':22',
    ]


def create_project_directory():
    run('mkdir -p ' + PROJECT_DIRECTORY)


def update_compose_file():
    put('./' + COMPOSE_FILE, PROJECT_DIRECTORY)


@task
def backup():
    backup_time = datetime.now().strftime('%Y-%m-%d_%H%M')
    with cd(BACKUP_DIRECTORY):
        command = 'tar -cjvf ztm-' + backup_time + \
            '.tar.bz2 ' + PROJECT_DIRECTORY
        env.run(command)

    command = 's3cmd sync ' + BACKUP_DIRECTORY + ' ' \
        's3://zendesk-tickets-machine'
    run(command)


def build():
    local('docker build -t prontotools/ztm-app -f ./compose/django/Dockerfile .')


def push():
    local('docker login')
    local('docker push prontotools/ztm-app')


@task
def deploy():
    build()
    push()
    create_project_directory()
    update_compose_file()
    with cd(PROJECT_DIRECTORY):
        env.run('docker-compose -f ' + COMPOSE_FILE + ' pull')
        env.run('docker-compose -f ' + COMPOSE_FILE + ' up -d')

@@ -894,38 +894,42 @@
 ef build():%0A    
-local(
+command = 
 'docker build -t
@@ -949,16 +949,29 @@
 ztm-app 
+' %5C%0A        '
 -f ./com
@@ -995,16 +995,34 @@
 rfile .'
+%0A    local(command
 )%0A%0A%0Adef 

Fix flake8 :bear: