'Return a dictionary of containers for the received repository\'s dependencies and
contents for display in the Tool Shed.'

def build_repository_containers(self, repository, changeset_revision, repository_dependencies, repository_metadata, exclude=None):

    if (exclude is None):
        exclude = []
    containers_dict = dict(datatypes=None, invalid_tools=None, readme_files=None, repository_dependencies=None, tool_dependencies=None, valid_tools=None, workflows=None, valid_data_managers=None)
    if repository_metadata:
        metadata = repository_metadata.metadata
        lock = threading.Lock()
        lock.acquire(True)
        try:
            folder_id = 0
            if metadata:
                if (('datatypes' not in exclude) and ('datatypes' in metadata)):
                    datatypes = metadata['datatypes']
                    (folder_id, datatypes_root_folder) = self.build_datatypes_folder(folder_id, datatypes)
                    containers_dict['datatypes'] = datatypes_root_folder
            if metadata:
                if (('invalid_repository_dependencies' not in exclude) and ('invalid_repository_dependencies' in metadata)):
                    invalid_repository_dependencies = metadata['invalid_repository_dependencies']
                    (folder_id, invalid_repository_dependencies_root_folder) = self.build_invalid_repository_dependencies_root_folder(folder_id, invalid_repository_dependencies)
                    containers_dict['invalid_repository_dependencies'] = invalid_repository_dependencies_root_folder
            if metadata:
                if (('invalid_tool_dependencies' not in exclude) and ('invalid_tool_dependencies' in metadata)):
                    invalid_tool_dependencies = metadata['invalid_tool_dependencies']
                    (folder_id, invalid_tool_dependencies_root_folder) = self.build_invalid_tool_dependencies_root_folder(folder_id, invalid_tool_dependencies)
                    containers_dict['invalid_tool_dependencies'] = invalid_tool_dependencies_root_folder
            if metadata:
                if (('invalid_tools' not in exclude) and ('invalid_tools' in metadata)):
                    invalid_tool_configs = metadata['invalid_tools']
                    (folder_id, invalid_tools_root_folder) = self.build_invalid_tools_folder(folder_id, invalid_tool_configs, changeset_revision, repository=repository, label='Invalid    tools')
                    containers_dict['invalid_tools'] = invalid_tools_root_folder
            if metadata:
                if (('readme_files' not in exclude) and ('readme_files' in metadata)):
                    readme_files_dict = readme_util.build_readme_files_dict(self.app, repository, changeset_revision, metadata)
                    (folder_id, readme_files_root_folder) = self.build_readme_files_folder(folder_id, readme_files_dict)
                    containers_dict['readme_files'] = readme_files_root_folder
            if ('repository_dependencies' not in exclude):
                (folder_id, repository_dependencies_root_folder) = self.build_repository_dependencies_folder(folder_id=folder_id, repository_dependencies=repository_dependencies, label='Repository    dependencies', installed=False)
                if repository_dependencies_root_folder:
                    containers_dict['repository_dependencies'] = repository_dependencies_root_folder
            if metadata:
                if (('tool_dependencies' not in exclude) and ('tool_dependencies' in metadata)):
                    tool_dependencies = metadata['tool_dependencies']
                    if ('orphan_tool_dependencies' in metadata):
                        orphan_tool_dependencies = metadata['orphan_tool_dependencies']
                        tool_dependencies.update(orphan_tool_dependencies)
                    if ('tools' not in exclude):
                        tools = metadata.get('tools', [])
                        tools.extend(metadata.get('invalid_tools', []))
                    (folder_id, tool_dependencies_root_folder) = self.build_tool_dependencies_folder(folder_id, tool_dependencies, missing=False, new_install=False)
                    containers_dict['tool_dependencies'] = tool_dependencies_root_folder
            if metadata:
                if (('tools' not in exclude) and ('tools' in metadata)):
                    valid_tools = metadata['tools']
                    (folder_id, valid_tools_root_folder) = self.build_tools_folder(folder_id, valid_tools, repository, changeset_revision, label='Valid    tools')
                    containers_dict['valid_tools'] = valid_tools_root_folder
            if metadata:
                if (('workflows' not in exclude) and ('workflows' in metadata)):
                    workflows = metadata['workflows']
                    (folder_id, workflows_root_folder) = self.build_workflows_folder(folder_id=folder_id, workflows=workflows, repository_metadata_id=repository_metadata.id, repository_id=None, label='Workflows')
                    containers_dict['workflows'] = workflows_root_folder
            if metadata:
                if (('data_manager' not in exclude) and ('data_manager' in metadata)):
                    data_managers = metadata['data_manager'].get('data_managers', None)
                    (folder_id, data_managers_root_folder) = self.build_data_managers_folder(folder_id, data_managers, label='Data    Managers')
                    containers_dict['valid_data_managers'] = data_managers_root_folder
                    error_messages = metadata['data_manager'].get('error_messages', None)
                    data_managers = metadata['data_manager'].get('invalid_data_managers', None)
                    (folder_id, data_managers_root_folder) = self.build_invalid_data_managers_folder(folder_id, data_managers, error_messages, label='Invalid    Data    Managers')
                    containers_dict['invalid_data_managers'] = data_managers_root_folder
        except Exception:
            log.exception('Exception    in    build_repository_containers')
        finally:
            lock.release()
    return containers_dict
