Exemple #1
0
    def _get_module_configs(self, module_path):
        """Parse and yield all module configs from a config file."""

        parser = cfg.ConfigParser()
        try:
            parser.read(module_path)
        except (cfg.ConfigParser.ParsingError,
                cfg.ConfigParser.CantOpenFile) as e:
            msg = str(e)
            raise dnf.exceptions.ConfigError(msg)

        # Check sections in the .module file that was just slurped up
        for section in parser.getData().keys():
            if section == 'main':
                continue

            try:
                module = self._build_module(parser, section, module_path)
            except (dnf.exceptions.RepoError, dnf.exceptions.ConfigError) as e:
                logger.warning(e)
                continue
            else:
                module.config_file = module_path

            yield module
Exemple #2
0
    def read(self, filename=None, priority=PRIO_DEFAULT):
        # :api
        if filename is None:
            filename = self._get_value('config_file_path')
        self._parser = cfg.ConfigParser()
        try:
            self._parser.read(filename)
        except RuntimeError as e:
            raise dnf.exceptions.ConfigError(_('Parsing file "%s" failed: %s') % (filename, e))
        except IOError as e:
            logger.warning(e)
        self._populate(self._parser, self._section, filename, priority)

        # update to where we read the file from
        self._set_value('config_file_path', filename, priority)
Exemple #3
0
    def _load(self, filename):
        parser = cfg.ConfigParser()
        try:
            parser.read(filename)
        except RuntimeError as e:
            raise dnf.exceptions.ConfigError('Parsing file "%s" failed: %s' %
                                             (filename, e))
        except IOError as e:
            logger.warning(e)

        self.commands._populate(parser, 'commands', filename,
                                dnf.conf.PRIO_AUTOMATICCONFIG)
        self.email._populate(parser, 'email', filename,
                             dnf.conf.PRIO_AUTOMATICCONFIG)
        self.emitters._populate(parser, 'emitters', filename,
                                dnf.conf.PRIO_AUTOMATICCONFIG)
        self.command_email._populate(parser, 'command_email', filename,
                                     dnf.conf.PRIO_AUTOMATICCONFIG)
        self._parser = parser
Exemple #4
0
    def _get_repos(self, repofn):
        """Parse and yield all repositories from a config file."""

        substs = self.conf.substitutions
        parser = cfg.ConfigParser()
        parser.setSubstitutions(substs)
        try:
            parser.read(repofn)
        except RuntimeError as e:
            raise dnf.exceptions.ConfigError(
                _('Parsing file "%s" failed: %s') % (repofn, e))
        except IOError as e:
            logger.warning(e)

        # Check sections in the .repo file that was just slurped up
        for section in parser.getData():

            if section == 'main':
                continue

            # Check the repo.id against the valid chars
            invalid = dnf.repo.repo_id_invalid(section)
            if invalid is not None:
                logger.warning(_("Bad id for repo: %s, byte = %s %d"), section,
                               section[invalid], invalid)
                continue

            try:
                thisrepo = self._build_repo(parser, ucd(section), repofn)
            except (dnf.exceptions.RepoError, dnf.exceptions.ConfigError) as e:
                logger.warning(e)
                continue
            else:
                thisrepo.repofile = repofn

            thisrepo._configure_from_options(self.opts)

            yield thisrepo