~osomon/moovida/launcher_no_rebuild

« back to all changes in this revision

Viewing changes to elisa-core/elisa/core/plugin_registry.py

  • Committer: Olivier Tilloy
  • Date: 2009-12-14 15:13:56 UTC
  • Revision ID: olivier@fluendo.com-20091214151356-73fmbfuyvzyztjd5
Fix disabling plugins (not tested).

Show diffs side-by-side

added added

removed removed

Lines of Context:
516
516
        def failed_to_disable(failure):
517
517
            failure.trap(PluginAlreadyDisabled)
518
518
 
519
 
        dfr = self.disable_plugin(plugin.key)
 
519
        dfr = self.disable_plugin(plugin)
520
520
        dfr.addErrback(failed_to_disable)
521
521
 
522
522
        def unload(result):
621
621
        dfr.addCallback(self._fire_registered_callbacks, plugin, True)
622
622
        return dfr
623
623
 
624
 
    def disable_plugin(self, plugin_name, permanent=False):
 
624
    def disable_plugin(self, plugin, permanent=False):
625
625
        """
626
626
        Disable a plugin.
627
627
 
628
 
        @param plugin_name: the name of the plugin to disable
629
 
        @type plugin_name:  C{str}
 
628
        @param plugin: the plugin to disable
630
629
        @param permanent: whether the plugin should be disabled permanently
631
 
                            (in the configuration), or only for this run
632
 
        @type  permanent: C{bool}
 
630
                          (in the configuration), or only for this run
 
631
        @type permanent:  C{bool}
633
632
 
634
633
        @return:            a deferred fired when the plugin is disabled
635
634
        @rtype:             L{twisted.internet.defer.Deferred}
636
635
        """
637
 
        plugin = self.get_plugin_by_name(plugin_name)
638
 
 
639
636
        def update_configuration(result):
640
637
            config = common.application.config
641
638
            disabled_plugins = config.get_option('disabled_plugins',
647
644
                                  section='general')
648
645
            return result
649
646
 
650
 
        def send_message(result):
651
 
            message = PluginStatusMessage(plugin_name,
652
 
                    PluginStatusMessage.ActionType.DISABLED)
653
 
            common.application.bus.send_message(message)
654
 
 
655
647
        try:
656
 
            if not self._plugin_status[plugin_name]:
657
 
                return defer.fail(PluginAlreadyDisabled(plugin_name))
 
648
            if not plugin.enabled:
 
649
                return defer.fail(PluginAlreadyDisabled(plugin.name))
658
650
        except KeyError:
659
 
            return defer.fail(PluginNotFound(plugin_name))
660
 
 
661
 
        self.info('Disabling plugin %s' % plugin_name)
662
 
        self._plugin_status[plugin_name] = False
663
 
 
664
 
        dfr = self._call_hook(plugin, 'disable')
665
 
        if permanent:
666
 
            dfr.addCallback(update_configuration)
 
651
            return defer.fail(PluginNotFound(plugin.name))
 
652
 
 
653
        self.info('Disabling plugin %s' % plugin.name)
 
654
        plugin.enabled = False
 
655
 
 
656
        dfr = plugin.call_hook('disable')
 
657
        #if permanent:
 
658
        #    dfr.addCallback(update_configuration)
667
659
        dfr.addCallback(self._fire_registered_callbacks, plugin, False)
668
 
        dfr.addCallback(send_message)
669
660
        return dfr
670
661
 
671
662
    def get_plugins(self):