Exemplo n.º 1
0
    def unregister_segment_plugin(self, plugin_instance):
        '''
        Removes the given plugin from the SegmentPool.
        '''

        #
        # NOTE: In many cases, the configuration of a given plugin may have
        # changed before we receive the call to unregister it. So, we'll look
        # for the plugin in all CFGS for this plugin's class.
        #

        if not self.segments:
            self.discover()

        if not isinstance(plugin_instance, SegmentBasePluginModel):
            raise ImproperlyConfigured(
                'Segment Plugins must subclasses of '
                'SegmentBasePluginModel. {0} is not.'.format(
                    plugin_instance.get_plugin_class_instance(
                    ).__class__.__name__))
        else:
            plugin_class_instance = plugin_instance.get_plugin_class_instance()
            if plugin_class_instance.allow_overrides:
                #
                # A segment plugin that doesn't allow overrides wouldn't be
                # registered in the first place.
                #
                plugin_class_name = plugin_class_instance.__class__.__name__

                if plugin_class_name in self.segments:
                    segment_class = self.segments[plugin_class_name]
                    segment_configs = segment_class[self.CFGS]
                    for configuration, data in segment_configs.items():
                        if plugin_instance in data[self.INSTANCES]:
                            # Found it! Now remove it...
                            data[self.INSTANCES].remove(plugin_instance)
                            self._sorted_segments = dict()

                            # Clean-up any empty elements caused by this removal...
                            if len(data[self.INSTANCES]) == 0:
                                # OK, this was the last one, so...
                                del segment_configs[configuration]

                                if len(segment_configs) == 0:
                                    # This too was the last one
                                    del self.segments[plugin_class_name]
            return

        try:
            cls = plugin_instance.get_plugin_class_instance(
            ).__class__.__name__
            raise PluginNotRegistered(
                'The segment plugin {0} cannot be '
                'unregistered because it is not currently registered in the '
                'SegmentPool.'.format(cls))
        except:
            raise PluginNotRegistered()
Exemplo n.º 2
0
    def unregister_plugin(self, plugin):
        """
        Unregisters the given plugin(s).

        If a plugin isn't already registered, this will raise PluginNotRegistered.
        """
        plugin_name = plugin.__name__
        if plugin_name not in self.plugins:
            raise PluginNotRegistered('The plugin %r is not registered' %
                                      plugin)
        del self.plugins[plugin_name]
Exemplo n.º 3
0
    def unregister_plugin(self, plugin_or_iterable):
        """
        Unregisters the given plugin(s).

        If a plugin isn't already registered, this will raise PluginNotRegistered.
        """
        if not hasattr(plugin_or_iterable,'__iter__'):
            plugin_or_iterable = [plugin_or_iterable]
        for plugin in plugin_or_iterable:
            plugin_name = plugin.__name__
            if plugin_name not in self.plugins:
                raise PluginNotRegistered('The plugin %s is not registered' % plugin_name)
            del self.plugins[plugin_name]
Exemplo n.º 4
0
    def unregister_plugin(self, plugin):
        """
        Unregisters the given plugin(s).

        If a plugin isn't already registered, this will raise PluginNotRegistered.
        """
        if hasattr(plugin, '__iter__'):
            warnings.warn(
                "Unregistering more than one plugin at once will be deprecated in 2.3",
                DeprecationWarning)
            for single_plugin in plugin:
                self.unregister_plugin(single_plugin)
            return
        plugin_name = plugin.__name__
        if plugin_name not in self.plugins:
            raise PluginNotRegistered('The plugin %r is not registered' %
                                      plugin)
        del self.plugins[plugin_name]