'Return a folder hierarchy containing valid tools.'

def build_tools_folder(self, folder_id, tool_dicts, repository, changeset_revision, valid=True, label='Valid    tools'):

    if tool_dicts:
        container_object_tool_id = 0
        folder_id += 1
        tools_root_folder = Folder(id=folder_id, key='root', label='root', parent=None)
        folder_id += 1
        folder = Folder(id=folder_id, key='tools', label=label, parent=tools_root_folder)
        if (self.app.name == 'galaxy'):
            folder.description = 'click    the    name    to    inspect    the    tool    metadata'
        tools_root_folder.folders.append(folder)
        container_object_tool_id += 1
        tool = Tool(id=container_object_tool_id, tool_config='', tool_id='', name='Name', description='Description', version='Version', profile='Minimum    Galaxy    Version', requirements='', repository_id='', changeset_revision='')
        folder.valid_tools.append(tool)
        if repository:
            repository_id = repository.id
            if (self.app.name == 'galaxy'):
                repository_installation_status = repository.status
            else:
                repository_installation_status = None
        else:
            repository_id = None
            repository_installation_status = None
        for tool_dict in tool_dicts:
            if (not isinstance(tool_dict, dict)):
                continue
            container_object_tool_id += 1
            requirements = tool_dict.get('requirements', None)
            if (requirements is not None):
                requirements_str = ''
                for requirement_dict in requirements:
                    try:
                        requirement_name = str(requirement_dict.get('name', 'unknown'))
                        requirement_type = str(requirement_dict.get('type', 'unknown'))
                    except Exception as e:
                        requirement_name = str(e)
                        requirement_type = 'unknown'
                    requirements_str += ('%s    (%s),    ' % (requirement_name, requirement_type))
                requirements_str = requirements_str.rstrip(',    ')
            else:
                requirements_str = 'none'
            try:
                tool_config = str(tool_dict.get('tool_config', 'missing'))
                tool_id = str(tool_dict.get('id', 'unknown'))
                name = str(tool_dict.get('name', 'unknown'))
                description = str(tool_dict.get('description', ''))
                version = str(tool_dict.get('version', 'unknown'))
                profile = str(tool_dict.get('profile', 'any'))
            except Exception as e:
                tool_config = str(e)
                tool_id = 'unknown'
                name = 'unknown'
                description = ''
                version = 'unknown'
            tool = Tool(id=container_object_tool_id, tool_config=tool_config, tool_id=tool_id, name=name, description=description, version=version, profile=profile, requirements=requirements_str, repository_id=repository_id, changeset_revision=changeset_revision, repository_installation_status=repository_installation_status)
            folder.valid_tools.append(tool)
    else:
        tools_root_folder = None
    return (folder_id, tools_root_folder)
