Пример #1
0
    def activate_plugin_with_version_check(self,
                                           plugin_info: PluginInfo,
                                           dep_track=None) -> BotPlugin:
        name = plugin_info.name
        config = self.get_plugin_configuration(name)

        if self.core_plugins is not None:
            if not check_enabled_core_plugin(name, plugin_info.details,
                                             self.core_plugins):
                log.warning(
                    'Core plugin "%s" has been skipped because it is not in CORE_PLUGINS in config.py.'
                    % name)
                return None

        if not check_python_plug_section(name, plugin_info.details):
            log.error('%s failed python version check.', name)
            return None

        if not check_errbot_plug_section(name, plugin_info.details):
            log.error('%s failed errbot version check.', name)
            return None

        depends_on = self._activate_plugin_dependencies(plugin_info, dep_track)

        obj = plugin_info.plugin_object

        obj.dependencies = depends_on

        try:
            if obj.get_configuration_template(
            ) is not None and config is not None:
                log.debug('Checking configuration for %s...', name)
                obj.check_configuration(config)
                log.debug('Configuration for %s checked OK.', name)
            obj.configure(config)  # even if it is None we pass it on
        except Exception as ex:
            log.exception(
                'Something is wrong with the configuration of the plugin %s',
                name)
            obj.config = None
            raise PluginConfigurationException(str(ex))
        add_plugin_templates_path(plugin_info.path)
        populate_doc(plugin_info)
        try:
            self.activatePluginByName(name, BOTPLUGIN_TAG)
            route(obj)
            return obj
        except Exception:
            plugin_info.activated = False  # Yapsy doesn't revert this in case of error
            remove_plugin_templates_path(plugin_info.path)
            log.error(
                "Plugin %s failed at activation stage, deactivating it...",
                name)
            self.deactivatePluginByName(name, BOTPLUGIN_TAG)
            raise
Пример #2
0
    def activate_plugin_with_version_check(self, plugin_info: PluginInfo, dep_track=None) -> BotPlugin:
        name = plugin_info.name
        config = self.get_plugin_configuration(name)

        if self.core_plugins is not None:
            if not check_enabled_core_plugin(name, plugin_info.details, self.core_plugins):
                log.warning('Core plugin "%s" has been skipped because it is not in CORE_PLUGINS in config.py.' % name)
                return None

        if not check_python_plug_section(name, plugin_info.details):
            log.error('%s failed python version check.', name)
            return None

        if not check_errbot_plug_section(name, plugin_info.details):
            log.error('%s failed errbot version check.', name)
            return None

        depends_on = self._activate_plugin_dependencies(plugin_info, dep_track)

        obj = plugin_info.plugin_object

        obj.dependencies = depends_on

        try:
            if obj.get_configuration_template() is not None and config is not None:
                log.debug('Checking configuration for %s...', name)
                obj.check_configuration(config)
                log.debug('Configuration for %s checked OK.', name)
            obj.configure(config)  # even if it is None we pass it on
        except Exception as ex:
            log.exception('Something is wrong with the configuration of the plugin %s', name)
            obj.config = None
            raise PluginConfigurationException(str(ex))
        add_plugin_templates_path(plugin_info.path)
        populate_doc(plugin_info)
        try:
            self.activatePluginByName(name, BOTPLUGIN_TAG)
            route(obj)
            return obj
        except Exception:
            plugin_info.activated = False  # Yapsy doesn't revert this in case of error
            remove_plugin_templates_path(plugin_info.path)
            log.error("Plugin %s failed at activation stage, deactivating it...", name)
            self.deactivatePluginByName(name, BOTPLUGIN_TAG)
            raise