'Attempt to locate a tool in the tool box. Note that `exact` only refers to the `tool_id`, not the `tool_version`.'

def get_tool(self, tool_id, tool_version=None, get_all_versions=False, exact=False):

    if tool_version:
        tool_version = str(tool_version)
    if (get_all_versions and exact):
        raise AssertionError('Cannot    specify    get_tool    with    both    get_all_versions    and    exact    as    True')
    if ('/repos/' in tool_id):
        tool_id_without_tool_shed = tool_id.split('/repos/')[1]
        available_tool_sheds = [urlparse(_) for _ in self.app.tool_shed_registry.tool_sheds.values()]
        available_tool_sheds = [url.geturl().replace((url.scheme + '://'), '', 1) for url in available_tool_sheds]
        tool_ids = [((tool_shed + 'repos/') + tool_id_without_tool_shed) for tool_shed in available_tool_sheds]
        if (tool_id in tool_ids):
            tool_ids.remove(tool_id)
        tool_ids.insert(0, tool_id)
    else:
        tool_ids = [tool_id]
    for tool_id in tool_ids:
        if ((tool_id in self._tools_by_id) and (not get_all_versions)):
            if (not tool_version):
                return self._tools_by_id[tool_id]
            elif (tool_version in self._tool_versions_by_id[tool_id]):
                return self._tool_versions_by_id[tool_id][tool_version]
        elif exact:
            continue
        rval = []
        tool_lineage = self._lineage_map.get(tool_id)
        if tool_lineage:
            lineage_tool_versions = tool_lineage.get_versions()
            for lineage_tool_version in lineage_tool_versions:
                lineage_tool = self._tool_from_lineage_version(lineage_tool_version)
                if lineage_tool:
                    rval.append(lineage_tool)
        if (not rval):
            for tool in self._tools_by_id.values():
                if (tool.old_id == tool_id):
                    rval.append(tool)
        if rval:
            if get_all_versions:
                return rval
            else:
                if tool_version:
                    for tool in rval:
                        if (tool.version == tool_version):
                            return tool
                return rval[0]
        if (tool_id in self._tools_by_id):
            if get_all_versions:
                return [self._tools_by_id[tool_id]]
            else:
                return self._tools_by_id[tool_id]
    return None
