Esempio n. 1
0
def readStartupConfig(configfile, root, releasever=None):
    """Parse Yum's main configuration file and return a
    :class:`StartupConf` instance.  This is required in order to
    access configuration settings required as Yum starts up.

    :param configfile: the path to yum.conf
    :param root: the base path to use for installation (typically '/')
    :return: A :class:`StartupConf` instance

    :raises: :class:`Errors.ConfigError` if a problem is detected with while parsing.
    """

    # ' xemacs syntax hack

    StartupConf.installroot.default = root
    startupconf = StartupConf()
    startupconf.config_file_path = configfile
    parser = ConfigParser()
    confpp_obj = ConfigPreProcessor(configfile)

    yumvars = _getEnvVar()
    confpp_obj._vars = yumvars
    startupconf.yumvars = yumvars

    try:
        parser.readfp(confpp_obj)
    except ParsingError, e:
        raise Errors.ConfigError("Parsing file failed: %s" % e)
Esempio n. 2
0
 def _getpluginconf(self, modname):
     '''Parse the plugin specific configuration file and return a
     IncludingConfigParser instance representing it. Returns None if there
     was an error reading or parsing the configuration file.
     '''
     for dir in self.pluginconfpath:
         conffilename = os.path.join(dir, modname + ".conf")
         if os.access(conffilename, os.R_OK):
             # Found configuration file
             break
         self.verbose_logger.log(
             logginglevels.INFO_2,
             _("Configuration file %s not found") % conffilename)
     else:  # for
         # Configuration files for the plugin not found
         self.verbose_logger.log(
             logginglevels.INFO_2,
             _("Unable to find configuration file for plugin %s") % modname)
         return None
     parser = ConfigParser()
     confpp_obj = ConfigPreProcessor(conffilename)
     try:
         parser.readfp(confpp_obj)
     except ParsingError, e:
         raise Errors.ConfigError("Couldn't parse %s: %s" %
                                  (conffilename, str(e)))
Esempio n. 3
0
def readVersionGroupsConfig(configfile="/etc/yum/version-groups.conf"):
    parser = ConfigParser()
    confpp_obj = ConfigPreProcessor(configfile)
    try:
        parser.readfp(confpp_obj)
    except ParsingError, e:
        raise Errors.ConfigError("Parsing file failed: %s" % e)
Esempio n. 4
0
def readStartupConfig(configfile, root):
    '''
    Parse Yum's main configuration file and return a StartupConf instance.
    
    This is required in order to access configuration settings required as Yum
    starts up.

    @param configfile: The path to yum.conf.
    @param root: The base path to use for installation (typically '/')
    @return: A StartupConf instance.

    May raise Errors.ConfigError if a problem is detected with while parsing.
    '''

    # ' xemacs syntax hack

    StartupConf.installroot.default = root
    startupconf = StartupConf()
    startupconf.config_file_path = configfile
    parser = ConfigParser()
    confpp_obj = ConfigPreProcessor(configfile)
    try:
        parser.readfp(confpp_obj)
    except ParsingError, e:
        raise Errors.ConfigError("Parsing file failed: %s" % e)
Esempio n. 5
0
    def registerCommand(self, command):
        """Register a new command.

        :param command: the command to register
        :raises: :class:`yum.Errors.ConfigError` if the registration
           of commands is not supported
        """
        if hasattr(self._base, 'registerCommand'):
            self._base.registerCommand(command)
        else:
            raise Errors.ConfigError(
                _('registration of commands not supported'))
Esempio n. 6
0
def readVersionGroupsConfig(configfile="/etc/yum/version-groups.conf"):
    """Parse the configuration file for version groups.
    
    :param configfile: the configuration file to read
    :return: a dictionary containing the parsed options
    """

    parser = ConfigParser()
    confpp_obj = ConfigPreProcessor(configfile)
    try:
        parser.readfp(confpp_obj)
    except ParsingError, e:
        raise Errors.ConfigError("Parsing file failed: %s" % e)
Esempio n. 7
0
 def blacklist(self):
     """Blacklist the message sender."""
     if (Defaults.PENDING_BLACKLIST_APPEND or
         (Defaults.DB_PENDING_BLACKLIST_APPEND and Defaults.DB_CONNECTION)):
         if Defaults.PENDING_BLACKLIST_APPEND:
             Util.append_to_file(self.append_address,
                                 Defaults.PENDING_BLACKLIST_APPEND)
         if Defaults.DB_PENDING_BLACKLIST_APPEND and Defaults.DB_CONNECTION:
             _username = Defaults.USERNAME.lower()
             _hostname = Defaults.HOSTNAME.lower()
             _recipient = _username + '@' + _hostname
             params = FilterParser.create_sql_params(
                 recipient=_recipient, username=_username,
                 hostname=_hostname, sender=self.append_address)
             Util.db_insert(Defaults.DB_CONNECTION,
                            Defaults.DB_PENDING_BLACKLIST_APPEND,
                            params)
     else:
         raise Errors.ConfigError(
             'PENDING_BLACKLIST_APPEND (or DB_CONNECTION+'
             'DB_PENDING_BLACKLIST_APPEND) not defined!')
Esempio n. 8
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)))
Esempio n. 9
0
    confpp_obj = ConfigPreProcessor(configfile)

    yumvars = _getEnvVar()
    confpp_obj._vars = yumvars
    startupconf.yumvars = yumvars

    try:
        parser.readfp(confpp_obj)
    except ParsingError, e:
        raise Errors.ConfigError("Parsing file failed: %s" % e)
    startupconf.populate(parser, 'main')

    # Check that plugin paths are all absolute
    for path in startupconf.pluginpath:
        if not path[0] == '/':
            raise Errors.ConfigError(
                "All plugin search paths must be absolute")
    # Stuff this here to avoid later re-parsing
    startupconf._parser = parser

    # setup the release ver here
    if releasever is None:
        releasever = _getsysver(startupconf.installroot,
                                startupconf.distroverpkg)
    startupconf.releasever = releasever

    uuidfile = '%s/%s/uuid' % (startupconf.installroot, startupconf.persistdir)
    startupconf.uuid = get_uuid(uuidfile)

    return startupconf

Esempio n. 10
0
 def registerCommand(self, command):
     if hasattr(self._base, 'registerCommand'):
         self._base.registerCommand(command)
     else:
         raise Errors.ConfigError(_('registration of commands not supported'))