'Inspect the list of repo_info_dicts for repository dependencies and append a repo_info_dict for each of
them to the list.  All repository_dependency entries in each of the received repo_info_dicts includes
all required repositories, so only one pass through this method is required to retrieve all repository
dependencies.'

def get_required_repo_info_dicts(self, tool_shed_url, repo_info_dicts):

    all_required_repo_info_dict = {}
    all_repo_info_dicts = []
    if repo_info_dicts:
        required_repository_tups = []
        for repo_info_dict in repo_info_dicts:
            if (repo_info_dict not in all_repo_info_dicts):
                all_repo_info_dicts.append(repo_info_dict)
            for (repository_name, repo_info_tup) in repo_info_dict.items():
                (description, repository_clone_url, changeset_revision, ctx_rev, repository_owner, repository_dependencies, tool_dependencies) = repository_util.get_repo_info_tuple_contents(repo_info_tup)
                if repository_dependencies:
                    for (key, val) in repository_dependencies.items():
                        if (key in ['root_key', 'description']):
                            continue
                        repository_components_tuple = container_util.get_components_from_key(key)
                        components_list = repository_util.extract_components_from_tuple(repository_components_tuple)
                        only_if_compiling_contained_td = 'False'
                        if (len(components_list) == 4):
                            only_if_compiling_contained_td = 'False'
                        elif (len(components_list) == 5):
                            only_if_compiling_contained_td = 'False'
                        if (not asbool(only_if_compiling_contained_td)):
                            if (components_list not in required_repository_tups):
                                required_repository_tups.append(components_list)
                        for components_list in val:
                            try:
                                only_if_compiling_contained_td = components_list[5]
                            except:
                                only_if_compiling_contained_td = 'False'
                            if (not asbool(only_if_compiling_contained_td)):
                                if (components_list not in required_repository_tups):
                                    required_repository_tups.append(components_list)
                else:
                    components_list = [tool_shed_url, repository_name, repository_owner, changeset_revision]
                    required_repository_tups.append(components_list)
            if required_repository_tups:
                encoded_required_repository_tups = []
                for required_repository_tup in required_repository_tups:
                    required_repository_tup = [str(item) for item in required_repository_tup]
                    encoded_required_repository_tups.append(encoding_util.encoding_sep.join(required_repository_tup))
                encoded_required_repository_str = encoding_util.encoding_sep2.join(encoded_required_repository_tups)
                encoded_required_repository_str = encoding_util.tool_shed_encode(encoded_required_repository_str)
                if repository_util.is_tool_shed_client(self.app):
                    tool_shed_url = common_util.get_tool_shed_url_from_tool_shed_registry(self.app, tool_shed_url)
                pathspec = ['repository', 'get_required_repo_info_dict']
                url = build_url(tool_shed_url, pathspec=pathspec)
                url = urlopen(Request(url)).geturl()
                request = Request(url, data=urlencode(dict(encoded_str=encoded_required_repository_str)))
                response = urlopen(request).read()
                if response:
                    try:
                        required_repo_info_dict = json.loads(response)
                    except Exception as e:
                        log.exception(e)
                        return all_repo_info_dicts
                    required_repo_info_dicts = []
                    for (k, v) in required_repo_info_dict.items():
                        if (k == 'repo_info_dicts'):
                            encoded_dict_strings = required_repo_info_dict['repo_info_dicts']
                            for encoded_dict_str in encoded_dict_strings:
                                decoded_dict = encoding_util.tool_shed_decode(encoded_dict_str)
                                required_repo_info_dicts.append(decoded_dict)
                        elif (k not in all_required_repo_info_dict):
                            all_required_repo_info_dict[k] = v
                        elif (v and (not all_required_repo_info_dict[k])):
                            all_required_repo_info_dict[k] = v
                        if required_repo_info_dicts:
                            for required_repo_info_dict in required_repo_info_dicts:
                                required_repo_info_dict_key = next(iter(required_repo_info_dict))
                                all_repo_info_dicts_keys = [next(iter(d)) for d in all_repo_info_dicts]
                                if (required_repo_info_dict_key not in all_repo_info_dicts_keys):
                                    all_repo_info_dicts.append(required_repo_info_dict)
                                else:
                                    tool_id = required_repo_info_dict[required_repo_info_dict_key][1]
                                    is_present = False
                                    for repo_info_dict in all_repo_info_dicts:
                                        for (k, v) in repo_info_dict.items():
                                            if (required_repo_info_dict_key == k):
                                                if (tool_id == v[1]):
                                                    is_present = True
                                                    break
                                    if (not is_present):
                                        all_repo_info_dicts.append(required_repo_info_dict)
                    all_required_repo_info_dict['all_repo_info_dicts'] = all_repo_info_dicts
    return all_required_repo_info_dict
