#!/usr/bin/python3
# creates and distributes an archive to
# your web servers, using the function deploy


from datetime import datetime
from fabric.api import env, local, put, run
from os import path


env.hosts = ['34.228.37.117', '54.234.227.98']
env.user = 'ubuntu'


def do_pack():
    """
    folder to .tgz
    """
    mydate = datetime.now()
    myfile = 'versions/web_static_{}{}{}{}{}{}.tgz'.format(
        mydate.year,
        mydate.month,
        mydate.day,
        mydate.hour,
        mydate.minute,
        mydate.second
    )
    local('mkdir -p versions')
    answer = local('tar -cvzf ' + myfile + ' web_static')
    if answer.succeeded:
        return myfile
    return None


def do_deploy(archive_path):
    """Deploy archive to web servers"""
    if not path.exists(archive_path) and not path.isfile(archive_path):
        return False

    myspath = archive_path.split('/')[1].split(".")
    i = myspath[0]

    try:
        # Upload the archive to the /tmp/ directory of the web server
        put(archive_path, '/tmp')

        # create dir
        run("sudo mkdir -p /data/web_static/releases/" + i + "/")

        # Uncompress the archive to the folder
        # /data/web_static/releases/<archive filename
        # without extension> on the web server
        run("sudo tar -xzf /tmp/" + i + ".tgz" +
            " -C /data/web_static/releases/" + i + "/")

        # Delete the archive from the web server
        run("sudo rm /tmp/" + i + ".tgz")

        run("sudo mv /data/web_static/releases/" + i +
            "/web_static/* /data/web_static/releases/" + i + "/")

        # Delete the symbolic link
        run("sudo rm -rf /data/web_static/releases/" + i + "/web_static")
        run("sudo rm -rf /data/web_static/current")

        # Create a new the symbolic link
        run("sudo ln -s /data/web_static/releases/" + i +
            "/ /data/web_static/current")
    except Exception:
        return False

    return True


def deploy():
    """
    Creates and distributes an archive to the web servers
    """
    myfile = do_pack()
    if myfile is None:
        return False
    return do_deploy(myfile)

3ae9248c984e7ce65290051eefe896f110480719
<mask token>


def do_deploy(archive_path):
    """Deploy archive to web servers"""
    if not path.exists(archive_path) and not path.isfile(archive_path):
        return False
    myspath = archive_path.split('/')[1].split('.')
    i = myspath[0]
    try:
        put(archive_path, '/tmp')
        run('sudo mkdir -p /data/web_static/releases/' + i + '/')
        run('sudo tar -xzf /tmp/' + i + '.tgz' +
            ' -C /data/web_static/releases/' + i + '/')
        run('sudo rm /tmp/' + i + '.tgz')
        run('sudo mv /data/web_static/releases/' + i +
            '/web_static/* /data/web_static/releases/' + i + '/')
        run('sudo rm -rf /data/web_static/releases/' + i + '/web_static')
        run('sudo rm -rf /data/web_static/current')
        run('sudo ln -s /data/web_static/releases/' + i +
            '/ /data/web_static/current')
    except Exception:
        return False
    return True


def deploy():
    """
    Creates and distributes an archive to the web servers
    """
    myfile = do_pack()
    if myfile is None:
        return False
    return do_deploy(myfile)

<mask token>


def do_pack():
    """
    folder to .tgz
    """
    mydate = datetime.now()
    myfile = 'versions/web_static_{}{}{}{}{}{}.tgz'.format(mydate.year,
        mydate.month, mydate.day, mydate.hour, mydate.minute, mydate.second)
    local('mkdir -p versions')
    answer = local('tar -cvzf ' + myfile + ' web_static')
    if answer.succeeded:
        return myfile
    return None


def do_deploy(archive_path):
    """Deploy archive to web servers"""
    if not path.exists(archive_path) and not path.isfile(archive_path):
        return False
    myspath = archive_path.split('/')[1].split('.')
    i = myspath[0]
    try:
        put(archive_path, '/tmp')
        run('sudo mkdir -p /data/web_static/releases/' + i + '/')
        run('sudo tar -xzf /tmp/' + i + '.tgz' +
            ' -C /data/web_static/releases/' + i + '/')
        run('sudo rm /tmp/' + i + '.tgz')
        run('sudo mv /data/web_static/releases/' + i +
            '/web_static/* /data/web_static/releases/' + i + '/')
        run('sudo rm -rf /data/web_static/releases/' + i + '/web_static')
        run('sudo rm -rf /data/web_static/current')
        run('sudo ln -s /data/web_static/releases/' + i +
            '/ /data/web_static/current')
    except Exception:
        return False
    return True


def deploy():
    """
    Creates and distributes an archive to the web servers
    """
    myfile = do_pack()
    if myfile is None:
        return False
    return do_deploy(myfile)

<mask token>
env.hosts = ['34.228.37.117', '54.234.227.98']
env.user = 'ubuntu'


def do_pack():
    """
    folder to .tgz
    """
    mydate = datetime.now()
    myfile = 'versions/web_static_{}{}{}{}{}{}.tgz'.format(mydate.year,
        mydate.month, mydate.day, mydate.hour, mydate.minute, mydate.second)
    local('mkdir -p versions')
    answer = local('tar -cvzf ' + myfile + ' web_static')
    if answer.succeeded:
        return myfile
    return None


def do_deploy(archive_path):
    """Deploy archive to web servers"""
    if not path.exists(archive_path) and not path.isfile(archive_path):
        return False
    myspath = archive_path.split('/')[1].split('.')
    i = myspath[0]
    try:
        put(archive_path, '/tmp')
        run('sudo mkdir -p /data/web_static/releases/' + i + '/')
        run('sudo tar -xzf /tmp/' + i + '.tgz' +
            ' -C /data/web_static/releases/' + i + '/')
        run('sudo rm /tmp/' + i + '.tgz')
        run('sudo mv /data/web_static/releases/' + i +
            '/web_static/* /data/web_static/releases/' + i + '/')
        run('sudo rm -rf /data/web_static/releases/' + i + '/web_static')
        run('sudo rm -rf /data/web_static/current')
        run('sudo ln -s /data/web_static/releases/' + i +
            '/ /data/web_static/current')
    except Exception:
        return False
    return True


def deploy():
    """
    Creates and distributes an archive to the web servers
    """
    myfile = do_pack()
    if myfile is None:
        return False
    return do_deploy(myfile)

from datetime import datetime
from fabric.api import env, local, put, run
from os import path
env.hosts = ['34.228.37.117', '54.234.227.98']
env.user = 'ubuntu'


def do_pack():
    """
    folder to .tgz
    """
    mydate = datetime.now()
    myfile = 'versions/web_static_{}{}{}{}{}{}.tgz'.format(mydate.year,
        mydate.month, mydate.day, mydate.hour, mydate.minute, mydate.second)
    local('mkdir -p versions')
    answer = local('tar -cvzf ' + myfile + ' web_static')
    if answer.succeeded:
        return myfile
    return None


def do_deploy(archive_path):
    """Deploy archive to web servers"""
    if not path.exists(archive_path) and not path.isfile(archive_path):
        return False
    myspath = archive_path.split('/')[1].split('.')
    i = myspath[0]
    try:
        put(archive_path, '/tmp')
        run('sudo mkdir -p /data/web_static/releases/' + i + '/')
        run('sudo tar -xzf /tmp/' + i + '.tgz' +
            ' -C /data/web_static/releases/' + i + '/')
        run('sudo rm /tmp/' + i + '.tgz')
        run('sudo mv /data/web_static/releases/' + i +
            '/web_static/* /data/web_static/releases/' + i + '/')
        run('sudo rm -rf /data/web_static/releases/' + i + '/web_static')
        run('sudo rm -rf /data/web_static/current')
        run('sudo ln -s /data/web_static/releases/' + i +
            '/ /data/web_static/current')
    except Exception:
        return False
    return True


def deploy():
    """
    Creates and distributes an archive to the web servers
    """
    myfile = do_pack()
    if myfile is None:
        return False
    return do_deploy(myfile)

#!/usr/bin/python3
# creates and distributes an archive to
# your web servers, using the function deploy


from datetime import datetime
from fabric.api import env, local, put, run
from os import path


env.hosts = ['34.228.37.117', '54.234.227.98']
env.user = 'ubuntu'


def do_pack():
    """
    folder to .tgz
    """
    mydate = datetime.now()
    myfile = 'versions/web_static_{}{}{}{}{}{}.tgz'.format(
        mydate.year,
        mydate.month,
        mydate.day,
        mydate.hour,
        mydate.minute,
        mydate.second
    )
    local('mkdir -p versions')
    answer = local('tar -cvzf ' + myfile + ' web_static')
    if answer.succeeded:
        return myfile
    return None


def do_deploy(archive_path):
    """Deploy archive to web servers"""
    if not path.exists(archive_path) and not path.isfile(archive_path):
        return False

    myspath = archive_path.split('/')[1].split(".")
    i = myspath[0]

    try:
        # Upload the archive to the /tmp/ directory of the web server
        put(archive_path, '/tmp')

        # create dir
        run("sudo mkdir -p /data/web_static/releases/" + i + "/")

        # Uncompress the archive to the folder
        # /data/web_static/releases/<archive filename
        # without extension> on the web server
        run("sudo tar -xzf /tmp/" + i + ".tgz" +
            " -C /data/web_static/releases/" + i + "/")

        # Delete the archive from the web server
        run("sudo rm /tmp/" + i + ".tgz")

        run("sudo mv /data/web_static/releases/" + i +
            "/web_static/* /data/web_static/releases/" + i + "/")

        # Delete the symbolic link
        run("sudo rm -rf /data/web_static/releases/" + i + "/web_static")
        run("sudo rm -rf /data/web_static/current")

        # Create a new the symbolic link
        run("sudo ln -s /data/web_static/releases/" + i +
            "/ /data/web_static/current")
    except Exception:
        return False

    return True


def deploy():
    """
    Creates and distributes an archive to the web servers
    """
    myfile = do_pack()
    if myfile is None:
        return False
    return do_deploy(myfile)
