'Update the received metadata_dict with information from the parsed datatypes_config.'

def generate_datatypes_metadata(self, tv, repository_files_dir, datatypes_config, metadata_dict):

    (tree, error_message) = xml_util.parse_xml(datatypes_config)
    if (tree is None):
        return metadata_dict
    root = tree.getroot()
    repository_datatype_code_files = []
    datatype_files = root.find('datatype_files')
    if (datatype_files is not None):
        for elem in datatype_files.findall('datatype_file'):
            name = elem.get('name', None)
            repository_datatype_code_files.append(name)
        metadata_dict['datatype_files'] = repository_datatype_code_files
    datatypes = []
    registration = root.find('registration')
    if (registration is not None):
        for elem in registration.findall('datatype'):
            converters = []
            display_app_containers = []
            datatypes_dict = {}
            display_in_upload = elem.get('display_in_upload', None)
            if display_in_upload:
                datatypes_dict['display_in_upload'] = display_in_upload
            dtype = elem.get('type', None)
            if dtype:
                datatypes_dict['dtype'] = dtype
            extension = elem.get('extension', None)
            if extension:
                datatypes_dict['extension'] = extension
            max_optional_metadata_filesize = elem.get('max_optional_metadata_filesize', None)
            if max_optional_metadata_filesize:
                datatypes_dict['max_optional_metadata_filesize'] = max_optional_metadata_filesize
            mimetype = elem.get('mimetype', None)
            if mimetype:
                datatypes_dict['mimetype'] = mimetype
            subclass = elem.get('subclass', None)
            if subclass:
                datatypes_dict['subclass'] = subclass
            for sub_elem in elem:
                if (sub_elem.tag == 'converter'):
                    tool_config = sub_elem.attrib['file']
                    target_datatype = sub_elem.attrib['target_datatype']
                    tool_config_path = hg_util.get_config_from_disk(tool_config, repository_files_dir)
                    full_path = os.path.abspath(tool_config_path)
                    (tool, valid, error_message) = tv.load_tool_from_config(self.app.security.encode_id(self.repository.id), full_path)
                    if (tool is None):
                        guid = None
                    else:
                        guid = suc.generate_tool_guid(self.repository_clone_url, tool)
                    converter_dict = dict(tool_config=tool_config, guid=guid, target_datatype=target_datatype)
                    converters.append(converter_dict)
                elif (sub_elem.tag == 'display'):
                    display_file = sub_elem.attrib['file']
                    display_app_dict = dict(display_file=display_file)
                    display_app_containers.append(display_app_dict)
            if converters:
                datatypes_dict['converters'] = converters
            if display_app_containers:
                datatypes_dict['display_app_containers'] = display_app_containers
            if datatypes_dict:
                datatypes.append(datatypes_dict)
        if datatypes:
            metadata_dict['datatypes'] = datatypes
    return metadata_dict
