

@task
@cmdopts([('branch=', 'b', 'Branch from which to publish'), ('docs-branch=', 'd', 'Docs branch to commit/push to'), ('git-repo=', 'g', 'Github repository to use'), ('deploy-key=', 'k', 'Deploy key to use')])
def publish_docs(options):
    'Publish current docs/site do paver.github.com'
    import os
    from subprocess import check_call, CalledProcessError
    from tempfile import mkdtemp, mkstemp
    current_repo = path(os.curdir).abspath()
    branch = getattr(options, 'branch', 'master')
    docs_branch = getattr(options, 'docs_branch', 'gh-pages')
    repo = getattr(options, 'git_repo', 'git@github.com:paver/paver.git')
    try:
        safe_clone = path(mkdtemp(prefix='paver-clone-'))
        docs_repo = path(mkdtemp(prefix='paver-docs-'))
        (fd, git) = mkstemp(prefix='tmp-git-ssh-')
        f = os.fdopen(fd, 'w')
        f.writelines(['#!/bin/sh', os.linesep, ('ssh%s $*' % ((' -i ' + options.deploy_key) if getattr(options, 'deploy_key', None) else ''))])
        f.close()
        os.chmod(git, int('777', 8))
        safe_clone.chdir()
        sh('git init')
        check_call(['git', 'remote', 'add', '-t', branch, '-f', 'origin', ('file://' + str(current_repo))], env={
            'GIT_SSH': git,
        })
        check_call(['git', 'checkout', branch], env={
            'GIT_SSH': git,
        })
        check_call(['python', os.path.join(str(current_repo), 'distutils_scripts', 'paver'), 'html'], env={
            'PYTHONPATH': os.path.join(str(current_repo)),
        })
        docs_repo.chdir()
        sh('git init')
        check_call(['git', 'remote', 'add', '-t', docs_branch, '-f', 'origin', repo], env={
            'GIT_SSH': options,
        })
        check_call(['git', 'checkout', docs_branch], env={
            'GIT_SSH': git,
        })
        check_call(['rsync', '-av', (os.path.join(str(safe_clone), 'paver', 'docs') + '/'), str(docs_repo)])
        sh('git add *')
        try:
            check_call(['git', 'commit', '-a', '-m', 'Commit auto-generated documentation'])
        except CalledProcessError:
            pass
        else:
            check_call(['git', 'push', 'origin', ('%s:%s' % (docs_branch, docs_branch))], env={
                'GIT_SSH': git,
            })
    finally:
        safe_clone.rmtree_p()
        docs_repo.rmtree_p()
        os.remove(git)

dataset/ETHPy150Open paver/paver/pavement.py publish_docs/VarMisuse@381/627 `git`->`options`