Example #1
0
def copy_database(host='', no_confirm=False):
    path = get_remote_dump(host=host)
    with settings(**get_host_settings(host)):
        msg = colors.red('Replace local database ' 'with dump?')
        if no_confirm or confirm(msg):
            restore_database(path=path,
                             dbsettings=env.database,
                             no_confirm=no_confirm)
Example #2
0
def install(host=''):
    """Instala SMVE en servidor"""
    h = get_host_settings(host)
    with settings(**h):
        create_virtualenv()
        create_project_paths()
        update_git()
        create_app_dirs()
        install_system_packages()
        install_pip_requirements()
        install_supervisor()
        configure_gunicorn()
Example #3
0
def install(host=''):
    """Instala SMVE en servidor"""
    h = get_host_settings(host)
    with settings(**h):
        create_virtualenv()
        create_project_paths()
        update_git()
        create_app_dirs()
        install_system_packages()
        install_pip_requirements()
        install_supervisor()
        configure_gunicorn()
Example #4
0
def get_remote_dump(host='', backupfile=SMVE_DEFAULT_BACKUP_PATH):
    h = get_host_settings(host)
    with settings(**h):
        print(
            colors.yellow(
                "Getting remote database: {database}".format(**env.database)))
        cmd = 'pg_dump -Fc {database} -f {backupfile}'
        cmd = cmd.format(backupfile=backupfile, **env.database)
        sudo('su postgres -c "{}"'.format(cmd))
        with hide('warnings'):
            get(backupfile, backupfile)
        run('rm -f %s' % backupfile)
    return backupfile
Example #5
0
def get_remote_dump(host='', backupfile=SMVE_DEFAULT_BACKUP_PATH):
    h = get_host_settings(host)
    with settings(**h):
        print(
            colors.yellow("Getting remote database: {database}".format(
                          **env.database))
        )
        cmd = 'pg_dump -Fc {database} -f {backupfile}'
        cmd = cmd.format(backupfile=backupfile, **env.database)
        sudo('su postgres -c "{}"'.format(cmd))
        with hide('warnings'):
            get(backupfile, backupfile)
        run('rm -f %s' % backupfile)
    return backupfile
Example #6
0
def install_server(host=''):
    h = get_host_settings(host)
    with settings(**h):

        install_deb_packages()
        if not command_available('pip'):
            install_pip()

        enusre_pip_package('virtualenvwrapper', with_sudo=True)
        create_project_paths()

        update_git()
        create_virtualenv()
        install_pip_requirements()

        install_supervisor()
Example #7
0
def install_server(host=''):
    h = get_host_settings(host)
    with settings(**h):

        install_deb_packages()
        if not command_available('pip'):
            install_pip()

        enusre_pip_package('virtualenvwrapper', with_sudo=True)
        create_project_paths()

        update_git()
        create_virtualenv()
        install_pip_requirements()

        install_supervisor()
Example #8
0
def freeze(host='', commit=False):
    """Conjela los requerimientos del virtualenv"""
    with settings(**get_host_settings(host)):
        print("Dumping", colors.yellow(DEV_REQUIEREMENTS_FILE))
        pip_freeze_to_file(DEV_REQUIEREMENTS_FILE)
        print("Dumping", colors.green(REQUIEREMENTS_FILE))
        pip_freeze_to_file(REQUIEREMENTS_FILE, filter_dev_only=True)
        if commit:
            local('git add {} {}'.format(
                DEV_REQUIEREMENTS_FILE, REQUIEREMENTS_FILE))
            with settings(warn_only=True):
                result = local(
                    'git commit -m "Requirements update"', capture=True)
            if result.failed:
                abort("Git up to date.")
            else:
                local('git push origin master')
Example #9
0
def freeze(host='', commit=False):
    """Conjela los requerimientos del virtualenv"""
    with settings(**get_host_settings(host)):
        print("Dumping", colors.yellow(DEV_REQUIEREMENTS_FILE))
        pip_freeze_to_file(DEV_REQUIEREMENTS_FILE)
        print("Dumping", colors.green(REQUIEREMENTS_FILE))
        pip_freeze_to_file(REQUIEREMENTS_FILE, filter_dev_only=True)
        if commit:
            local('git add {} {}'.format(DEV_REQUIEREMENTS_FILE,
                                         REQUIEREMENTS_FILE))
            with settings(warn_only=True):
                result = local('git commit -m "Requirements update"',
                               capture=True)
            if result.failed:
                abort("Git up to date.")
            else:
                local('git push origin master')
Example #10
0
def get_remote_media(host='', no_confirm=False):
    """Gets remote media"""
    media_cmd = 'python manage.py diffsettings | grep MEDIA_ROOT | cut -d = -f 2'
    with settings(**get_host_settings(host)):
        if no_confirm or confirm(colors.red('Replace local media with dump?', True)):
            with cd(os.path.join(env.repo_path, 'src/pysmve/nguru')):
                with hide():
                    local_media_root = extract_path_from_stdout(
                        local(media_cmd, True))

                    local_media_root = os.path.abspath(
                        os.path.join(local_media_root, '..'))
                    with prefix(env.venv_prefix):
                        remote_meida_root = extract_path_from_stdout(
                            run(media_cmd, True))

                print(remote_meida_root, '=>', local_media_root)
                with hide('warnings'):
                    get(remote_meida_root, local_media_root)
Example #11
0
def get_remote_media(host='', no_confirm=False):
    """Gets remote media"""
    media_cmd = 'python manage.py diffsettings | grep MEDIA_ROOT | cut -d = -f 2'
    with settings(**get_host_settings(host)):
        if no_confirm or confirm(
                colors.red('Replace local media with dump?', True)):
            with cd(os.path.join(env.repo_path, 'src/pysmve/nguru')):
                with hide():
                    local_media_root = extract_path_from_stdout(
                        local(media_cmd, True))

                    local_media_root = os.path.abspath(
                        os.path.join(local_media_root, '..'))
                    with prefix(env.venv_prefix):
                        remote_meida_root = extract_path_from_stdout(
                            run(media_cmd, True))

                print(remote_meida_root, '=>', local_media_root)
                with hide('warnings'):
                    get(remote_meida_root, local_media_root)
Example #12
0
def update(host='', release=''):
    """Updates deployment to upstream git version or tag.
    Recommended use for release:

    $ git tag <version>
    $ fab update:<server_from_fabsettings_HOST>,<version>

    """

    h = get_host_settings(host)

    available_tags = get_tags()
    if release:
        if release not in available_tags:
            abort((
                "Release {} is not a valid tag (Latest tags were: {})."
                " Run fab tag first").format(
                    colors.red(release, True),
                    colors.green('; '.join(available_tags[-3:]))
                )
            )
    else:
        if confirm('Create tag from current code?'):
            release = tag()

    local('git push origin --tags')
    local('git push origin master')
    # update local repo (needed?)
    local('git fetch')
    with settings(**h):
        procs = ('poll_mara', 'send_sms')
        with hold(procs):
            update_git(tag=release)
            install_pip_requirements()
            syncdb()
            migrate()
            update_static_media()
            update_permissions()
            restart_webserver(host)
Example #13
0
def update(host='', release=''):
    """Updates deployment to upstream git version or tag.
    Recommended use for release:

    $ git tag <version>
    $ fab update:<server_from_fabsettings_HOST>,<version>

    """

    h = get_host_settings(host)

    available_tags = get_tags()
    if release:
        if release not in available_tags:
            abort(("Release {} is not a valid tag (Latest tags were: {})."
                   " Run fab tag first").format(
                       colors.red(release, True),
                       colors.green('; '.join(available_tags[-3:]))))
    else:
        if confirm('Create tag from current code?'):
            release = tag()

    local('git push origin --tags')
    local('git push origin master')
    # update local repo (needed?)
    local('git fetch')
    with settings(**h):
        procs = ('poll_mara', 'send_sms')
        with hold(procs):
            update_git(tag=release)
            install_pip_requirements()
            syncdb()
            migrate()
            update_static_media()
            update_permissions()
            restart_webserver(host)
Example #14
0
def copy_database(host='', no_confirm=False):
    path = get_remote_dump(host=host)
    with settings(**get_host_settings(host)):
        msg = colors.red('Replace local database ''with dump?')
        if no_confirm or confirm(msg):
            restore_database(path=path, dbsettings=env.database, no_confirm=no_confirm)
Example #15
0
def restart_webserver(host=''):
    """Restart webserver"""
    h = get_host_settings(host)
    with settings(**h):
        sudo('supervisorctl restart gunicorn_production')
Example #16
0
def shell(host=''):
    """Abre shell remota en host"""
    from fabric.operations import open_shell
    h = get_host_settings(host)
    with settings(**h):
        open_shell()
Example #17
0
def restart_webserver(host=''):
    """Restart webserver"""
    h = get_host_settings(host)
    with settings(**h):
        sudo('supervisorctl restart gunicorn_production')
Example #18
0
def pip_uninstall(host='', package=''):
    if not package:
        abort("Please provide a package to uninstall")
    with settings(**get_host_settings(host)):
        with prefix(env.venv_prefix):
            run('pip uninstall -y {}'.format(package))
Example #19
0
def pip_uninstall(host='', package=''):
    if not package:
        abort("Please provide a package to uninstall")
    with settings(**get_host_settings(host)):
        with prefix(env.venv_prefix):
            run('pip uninstall -y {}'.format(package))
Example #20
0
def install_sentry(host=''):
    with settings(**get_host_settings(host)):
        run("ls")
Example #21
0
def install_sentry(host=''):
    with settings(**get_host_settings(host)):
        run("ls")
Example #22
0
def get_remote_all(host='', no_confirm=False):
    get_host_settings(host)  # Check
    if no_confirm or confirm(colors.red('Replace local data with remote?')):
        copy_database(host=host, no_confirm=no_confirm)
        get_remote_media(host=host, no_confirm=no_confirm)
Example #23
0
def get_remote_all(host='', no_confirm=False):
    get_host_settings(host)  # Check
    if no_confirm or confirm(colors.red('Replace local data with remote?')):
        copy_database(host=host, no_confirm=no_confirm)
        get_remote_media(host=host, no_confirm=no_confirm)
Example #24
0
def shell(host=''):
    """Abre shell remota en host"""
    from fabric.operations import open_shell
    h = get_host_settings(host)
    with settings(**h):
        open_shell()
Example #25
0
def pip_list(host=''):
    with settings(**get_host_settings(host)):
        with prefix(env.venv_prefix):
            run('pip freeze')
Example #26
0
def pip_list(host=''):
    with settings(**get_host_settings(host)):
        with prefix(env.venv_prefix):
            run('pip freeze')