'Process the sniffers element from a parsed a datatypes XML file located at root_dir/config (if processing the Galaxy
distributed config) or contained within an installed Tool Shed repository.  If deactivate is True, an installed Tool
Shed repository that includes custom sniffers is being deactivated or uninstalled, so appropriate loaded sniffers will
be removed from the 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 at server startup, its contents
cannot be overridden by newly introduced conflicting sniffers.'

def load_datatype_sniffers(self, root, deactivate=False, handling_proprietary_datatypes=False, override=False):

    sniffer_elem_classes = [e.attrib['type'] for e in self.sniffer_elems]
    sniffers = root.find('sniffers')
    if (sniffers is not None):
        for elem in sniffers.findall('sniffer'):
            ok = True
            dtype = elem.get('type', None)
            if (dtype is not None):
                try:
                    fields = dtype.split(':')
                    datatype_module = fields[0]
                    datatype_class_name = fields[1]
                    module = None
                except Exception as e:
                    self.log.exception('Error    determining    datatype    class    or    module    for    dtype    %s', str(dtype))
                    ok = False
                if ok:
                    if handling_proprietary_datatypes:
                        for imported_module in self.imported_modules:
                            if hasattr(imported_module, datatype_class_name):
                                module = imported_module
                                break
                    if (module is None):
                        try:
                            module = __import__(datatype_module)
                            for comp in datatype_module.split('.')[1:]:
                                module = getattr(module, comp)
                        except Exception as e:
                            self.log.exception("Error    importing    datatype    class    for    '%s'", str(dtype))
                            ok = False
                    if ok:
                        try:
                            aclass = getattr(module, datatype_class_name)()
                        except Exception as e:
                            self.log.exception('Error    calling    method    %s    from    class    %s', str(datatype_class_name), str(module))
                            ok = False
                        if ok:
                            if deactivate:
                                sniffer_class = elem.get('type', None)
                                if (sniffer_class is not None):
                                    for (index, s_e_c) in enumerate(sniffer_elem_classes):
                                        if (sniffer_class == s_e_c):
                                            del self.sniffer_elems[index]
                                            sniffer_elem_classes = [elem.attrib['type'] for elem in self.sniffer_elems]
                                            self.log.debug(("Removed    sniffer    element    for    datatype    '%s'" % str(dtype)))
                                            break
                                    for sniffer_class in self.sniff_order:
                                        if (sniffer_class.__class__ == aclass.__class__):
                                            self.sniff_order.remove(sniffer_class)
                                            self.log.debug(("Removed    sniffer    class    for    datatype    '%s'    from    sniff    order" % str(dtype)))
                                            break
                            else:
                                conflict = False
                                for (conflict_loc, sniffer_class) in enumerate(self.sniff_order):
                                    if (sniffer_class.__class__ == aclass.__class__):
                                        conflict = True
                                        if override:
                                            del self.sniff_order[conflict_loc]
                                            self.log.debug(("Removed    conflicting    sniffer    for    datatype    '%s'" % dtype))
                                        break
                                if conflict:
                                    if override:
                                        self.sniff_order.append(aclass)
                                        self.log.debug(("Loaded    sniffer    for    datatype    '%s'" % dtype))
                                else:
                                    self.sniff_order.append(aclass)
                                    self.log.debug(("Loaded    sniffer    for    datatype    '%s'" % dtype))
                                sniffer_class = elem.get('type', None)
                                if (sniffer_class is not None):
                                    if (sniffer_class not in sniffer_elem_classes):
                                        self.sniffer_elems.append(elem)
