'Compares a tool version with the tool version from a job (from ToolRunner).'

def _compare_tool_version(self, job):

    tool_id = job.tool_id
    tool_version = job.tool_version
    message = ''
    try:
        (select_field, tools, tool) = self.app.toolbox.get_tool_components(tool_id, tool_version=tool_version, get_loaded_tools_by_lineage=False, set_selected=True)
        if (tool is None):
            raise exceptions.MessageException(("This    dataset    was    created    by    an    obsolete    tool    (%s).    Can't    re-run." % tool_id))
        if (((self.id != tool_id) and (self.old_id != tool_id)) or (self.version != tool_version)):
            if (self.id == tool_id):
                if (tool_version is None):
                    message = ''
                else:
                    message = ('This    job    was    run    with    tool    version    "%s",    which    is    not    available.        ' % tool_version)
                    if (len(tools) > 1):
                        message += 'You    can    re-run    the    job    with    the    selected    tool    or    choose    another    version    of    the    tool.'
                    else:
                        message += 'You    can    re-run    the    job    with    this    tool    version,    which    is    a    different    version    of    the    original    tool.'
            else:
                new_tool_shed_url = ('%s/%s/' % (tool.tool_shed_repository.get_sharable_url(tool.app), tool.tool_shed_repository.changeset_revision))
                old_tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(self.app, tool_id.split('/repos/')[0])
                old_tool_shed_url = ('%s/view/%s/%s/' % (old_tool_shed_url, tool.repository_owner, tool.repository_name))
                message = ('This    job    was    run    with    <a    href="%s"    target="_blank">tool    id    "%s"</a>,    version    "%s",    which    is    not    available.        ' % (old_tool_shed_url, tool_id, tool_version))
                if (len(tools) > 1):
                    message += ('You    can    re-run    the    job    with    the    selected    <a    href="%s"    target="_blank">tool    id    "%s"</a>    or    choose    another    derivation    of    the    tool.' % (new_tool_shed_url, self.id))
                else:
                    message += ('You    can    re-run    the    job    with    <a    href="%s"    target="_blank">tool    id    "%s"</a>,    which    is    a    derivation    of    the    original    tool.' % (new_tool_shed_url, self.id))
    except Exception as e:
        raise exceptions.MessageException(str(e))
    return message
