'Install the latest installable revision of a repository that has been previously installed.'

@web.expose
@web.require_admin
def install_latest_repository_revision(self, trans, **kwd):

    message = escape(kwd.get('message', ''))
    status = kwd.get('status', 'done')
    repository_id = kwd.get('id', None)
    if (repository_id is not None):
        repository = repository_util.get_installed_tool_shed_repository(trans.app, repository_id)
        if (repository is not None):
            tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(trans.app, str(repository.tool_shed))
            name = str(repository.name)
            owner = str(repository.owner)
            params = dict(galaxy_url=web.url_for('/', qualified=True), name=name, owner=owner)
            pathspec = ['repository', 'get_latest_downloadable_changeset_revision']
            raw_text = util.url_get(tool_shed_url, password_mgr=self.app.tool_shed_registry.url_auth(tool_shed_url), pathspec=pathspec, params=params)
            url = util.build_url(tool_shed_url, pathspec=pathspec, params=params)
            latest_downloadable_revision = json.loads(raw_text)
            if (latest_downloadable_revision == hg_util.INITIAL_CHANGELOG_HASH):
                message = ('Error    retrieving    the    latest    downloadable    revision    for    this    repository    via    the    url    <b>%s</b>.' % url)
                status = 'error'
            else:
                tmp_clone_url = util.build_url(tool_shed_url, pathspec=['repos', owner, name])
                tmp_repo_info_tuple = (None, tmp_clone_url, latest_downloadable_revision, None, owner, None, None)
                (installed_repository, installed_changeset_revision) = repository_util.repository_was_previously_installed(trans.app, tool_shed_url, name, tmp_repo_info_tuple, from_tip=False)
                if installed_repository:
                    current_changeset_revision = str(installed_repository.changeset_revision)
                    message = ('Revision    <b>%s</b>    of    repository    <b>%s</b>    owned    by    <b>%s</b>    has    already    been    installed.' % (latest_downloadable_revision, name, owner))
                    if (current_changeset_revision != latest_downloadable_revision):
                        message += ('        The    current    changeset    revision    is    <b>%s</b>.' % current_changeset_revision)
                    status = 'error'
                else:
                    params = dict(name=name, owner=owner, changeset_revisions=str(latest_downloadable_revision), galaxy_url=web.url_for('/', qualified=True))
                    pathspec = ['repository', 'install_repositories_by_revision']
                    url = util.build_url(tool_shed_url, pathspec=pathspec, params=params)
                    return trans.response.send_redirect(url)
        else:
            message = ('Cannot    locate    installed    tool    shed    repository    with    encoded    id    <b>%s</b>.' % str(repository_id))
            status = 'error'
    else:
        message = 'The    request    parameters    did    not    include    the    required    encoded    <b>id</b>    of    installed    repository.'
        status = 'error'
    return trans.response.send_redirect(web.url_for(controller='admin_toolshed', action='browse_repositories', message=message, status=status))
