def push_source(
    new_source_dir, current_source_dir=None, chown=None, chmod=None,
):
    logger.info(u"Rsyncing the src to %s", env.host_string)

    # Copy the current source to our new source directory (preserving file
    # attributes) so that we can use rsync to push only the changed files
    sudo("mkdir --parents %s" % new_source_dir)

    if current_source_dir:
        logger.info(
            "Copying existing source as a base from: %s",
            current_source_dir,
        )
        for copy_dir in COPY_DIRS:
            from_dir = os.path.join(current_source_dir, copy_dir)
            to_dir = os.path.join(new_source_dir, copy_dir)
            sudo("cp -r --dereference --preserve %s %s" % (from_dir, to_dir))

        # Remove copied .pyc files and empty directories
        sudo('find %s -name "*.pyc" -delete' % current_source_dir)
        sudo('find %s -type d -empty -delete' % current_source_dir)

    # Give the rsync user permissions to change file attributes
    logger.info("Giving current user permission to modify files")
    sudo("chown -R %s %s" % (env.user, new_source_dir))

    # Rsync the source to the new directory
    logger.info(u"Rsync beginning")
    start = time.time()

    def do_rsync():
        # rsync_project already uses the rsync options:
        # http://docs.fabfile.org/en/1.4.0/api/contrib/project.html#fabric.contrib.project.rsync_project  # noqa
        # --perms
        # --times
        # --human-readable
        # --recursive
        # --verbose
        # --compress
        extra_opts = [
            '--links',
            '--no-perms',
            '--executability',
            '--no-verbose',
            '--stats',
            '''--rsh="ssh -o 'StrictHostKeyChecking no'"''',
        ]
        return rsync_project(
            '%s' % new_source_dir,
            local_dir='../.',
            exclude=EXCLUDES,
            delete=True,
            extra_opts=' '.join(extra_opts),
        )
    output = do_rsync()
    if output.failed:
        logger.warning(
            "Rsync exited with code: %s. Retrying" % output.return_code
        )
        start = time.time()
        output = do_rsync()
        if output.failed:
            logger.critical("Rsync failed again. Aborting.")
            exit(1)

    logger.info("Rsync complete. Took %s seconds", time.time() - start)
    logger.info("Rsync stats: %s", output)

    if chown:
        sudo("chown -R %s %s" % (chown, new_source_dir))
    if chmod is not None:
        if type(chmod) == int:
            # This is an octal permission mask. Convert it to a string
            # representation.
            chmod = "%o" % chmod
        sudo("chmod -R %s %s" % (chmod, new_source_dir))
Rsync the current project to `new_source_dir`, optionally first copying the
dataset/ETHPy150Open winhamwr/neckbeard/neckbeard/brain_wrinkles/pstat/app.py/push_source