Exemplo n.º 1
0
    def confBool(self, section, opt, default=None):
        '''Read a boolean value from the plugin's own configuration file

        @param section: Configuration file section to read.
        @param opt: Option name to read.
        @param default: Value to read if option is missing.
        @return: Boolean option value read, or default if option was missing or
            could not be parsed.
        '''
        return config.getOption(self._conf, section, opt, config.BoolOption(default))
Exemplo n.º 2
0
    def confBool(self, section, opt, default=None):
        """Read a boolean value from the plugin's own configuration file

        :param section: configuration file section to read
        :param opt: option name to read
        :param default: value to read if the option is missing
        :return: boolean option value read, or *default* if the option
            was missing or could not be parsed
        """
        return config.getOption(self._conf, section, opt,
                                config.BoolOption(default))
Exemplo n.º 3
0
    def _loadplugin(self, modulefile, types):
        '''Attempt to import a plugin module and register the hook methods it
        uses.
        '''
        dir, modname = os.path.split(modulefile)
        modname = modname.split('.py')[0]

        conf = self._getpluginconf(modname)
        if (not conf or
            (not config.getOption(conf, 'main', 'enabled',
                                  config.BoolOption(False))
             and not self._plugin_cmdline_match(modname, self.enabledPlugins,
                                                self._used_enable_plugin))):
            self.verbose_logger.debug(
                _('Not loading "%s" plugin, as it is disabled'), modname)
            return

        try:
            fp, pathname, description = imp.find_module(modname, [dir])
            try:
                module = imp.load_module(modname, fp, pathname, description)
            finally:
                fp.close()
        except:
            if self.verbose_logger.isEnabledFor(logginglevels.DEBUG_4):
                raise  # Give full backtrace:
            self.verbose_logger.error(
                _('Plugin "%s" can\'t be imported') % modname)
            return

        # Check API version required by the plugin
        if not hasattr(module, 'requires_api_version'):
            self.verbose_logger.error(
                _('Plugin "%s" doesn\'t specify required API version') %
                modname)
            return
        if not apiverok(API_VERSION, module.requires_api_version):
            self.verbose_logger.error(
                _('Plugin "%s" requires API %s. Supported API is %s.') % (
                    modname,
                    module.requires_api_version,
                    API_VERSION,
                ))
            return

        # Check plugin type against filter
        plugintypes = getattr(module, 'plugin_type', ALL_TYPES)
        if not isinstance(plugintypes, (list, tuple)):
            plugintypes = (plugintypes, )

        if len(plugintypes) < 1:
            return
        for plugintype in plugintypes:
            if id(plugintype) == id(TYPE_INTERFACE):
                self.verbose_logger.log(
                    logginglevels.INFO_2,
                    'Plugin "%s" uses deprecated constant '
                    'TYPE_INTERFACE.\nPlease use TYPE_INTERACTIVE '
                    'instead.', modname)

            if plugintype not in types:
                return

        #  This should really work like enable/disable repo. and be based on the
        # cmd line order ... but the API doesn't really allow that easily.
        # FIXME: Fix for 4.*
        if (self._plugin_cmdline_match(modname, self.disabledPlugins,
                                       self._used_disable_plugin)
                and not self._plugin_cmdline_match(
                    modname, self.enabledPlugins, self._used_enable_plugin)):
            return

        self.verbose_logger.log(logginglevels.DEBUG_3,
                                _('Loading "%s" plugin'), modname)

        # Store the plugin module and its configuration file
        if modname not in self._plugins:
            self._plugins[modname] = (module, conf)
        else:
            raise Errors.ConfigError(_('Two or more plugins with the name "%s" ' \
                    'exist in the plugin search path') % modname)

        for slot in SLOTS:
            funcname = slot + '_hook'
            if hasattr(module, funcname):
                self._pluginfuncs[slot].append(
                    (modname, getattr(module, funcname)))