'Parse a custom datatypes config (a datatypes_conf.xml file included in an installed
tool shed repository) and add information to appropriate element attributes that will
enable custom datatype class modules, datatypes converters and display applications
to be discovered and properly imported by the datatypes registry.  The value of override
will be False when a tool shed repository is being installed.  Since installation is
occurring after the datatypes registry has been initialized, the registry\'s contents
cannot be overridden by conflicting data types.'

def alter_config_and_load_prorietary_datatypes(self, datatypes_config, relative_install_dir, deactivate=False, override=True):

    (tree, error_message) = xml_util.parse_xml(datatypes_config)
    if (tree is None):
        return (None, None)
    datatypes_config_root = tree.getroot()
    registration = datatypes_config_root.find('registration')
    if (registration is None):
        return (None, None)
    (converter_path, display_path) = self.get_converter_and_display_paths(registration, relative_install_dir)
    if converter_path:
        registration.attrib['proprietary_converter_path'] = converter_path
    if display_path:
        registration.attrib['proprietary_display_path'] = display_path
    relative_path_to_datatype_file_name = None
    datatype_files = datatypes_config_root.find('datatype_files')
    datatype_class_modules = []
    if (datatype_files is not None):
        for elem in datatype_files.findall('datatype_file'):
            datatype_file_name = elem.get('name', None)
            if datatype_file_name:
                for (root, dirs, files) in os.walk(relative_install_dir):
                    if (root.find('.hg') < 0):
                        for name in files:
                            if (name == datatype_file_name):
                                datatype_class_modules.append(os.path.join(root, name))
                                break
                break
        if datatype_class_modules:
            for relative_path_to_datatype_file_name in datatype_class_modules:
                (datatype_file_name_path, datatype_file_name) = os.path.split(relative_path_to_datatype_file_name)
                for elem in registration.findall('datatype'):
                    dtype = elem.get('type', None)
                    if dtype:
                        fields = dtype.split(':')
                        proprietary_datatype_module = fields[0]
                        if (proprietary_datatype_module.find('.') >= 0):
                            proprietary_datatype_module = proprietary_datatype_module.split('.')[(-1)]
                        elem.attrib['proprietary_path'] = os.path.abspath(datatype_file_name_path)
                        elem.attrib['proprietary_datatype_module'] = proprietary_datatype_module
    self.app.datatypes_registry.load_datatypes(root_dir=self.app.config.root, config=datatypes_config_root, deactivate=deactivate, override=override)
    return (converter_path, display_path)
