'Generate a repository dependencies dictionary based on valid information defined in the received
repository_dependencies_config.  This method is called from the tool shed as well as from Galaxy.'

def generate_repository_dependency_metadata(self, repository_dependencies_config, metadata_dict):

    error_message = ''
    (tree, error_message) = xml_util.parse_xml(repository_dependencies_config)
    if (tree is None):
        xml_is_valid = False
    else:
        root = tree.getroot()
        xml_is_valid = (root.tag == 'repositories')
    if xml_is_valid:
        invalid_repository_dependencies_dict = dict(description=root.get('description'))
        invalid_repository_dependency_tups = []
        valid_repository_dependencies_dict = dict(description=root.get('description'))
        valid_repository_dependency_tups = []
        for repository_elem in root.findall('repository'):
            (repository_dependency_tup, repository_dependency_is_valid, err_msg) = self.handle_repository_elem(repository_elem, only_if_compiling_contained_td=False)
            if repository_dependency_is_valid:
                valid_repository_dependency_tups.append(repository_dependency_tup)
            else:
                (toolshed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td) = repository_dependency_tup
                repository_dependency_tup = (toolshed, name, owner, changeset_revision, prior_installation_required, only_if_compiling_contained_td, err_msg)
                invalid_repository_dependency_tups.append(repository_dependency_tup)
                error_message += err_msg
        if invalid_repository_dependency_tups:
            invalid_repository_dependencies_dict['repository_dependencies'] = invalid_repository_dependency_tups
            metadata_dict['invalid_repository_dependencies'] = invalid_repository_dependencies_dict
        if valid_repository_dependency_tups:
            valid_repository_dependencies_dict['repository_dependencies'] = valid_repository_dependency_tups
            metadata_dict['repository_dependencies'] = valid_repository_dependencies_dict
    return (metadata_dict, error_message)
