Ejemplo n.º 1
0
    def test_compat(self):
        s = dedent("""
            [sec1]
            a=1


            [sec2]

            b=2

            c=3


            """)
        cfg = ConfigParser()
        cfg.readfp(StringIO(s))
        tidy(cfg)
        self.assertEqual(str(cfg.data), dedent("""\
            [sec1]
            a=1

            [sec2]
            b=2

            c=3
            """))
Ejemplo n.º 2
0
 def get_koji_session(self, login=True):
     """ Return an authenticated koji session """
     import koji
     from iniparse.compat import ConfigParser
     config = ConfigParser()
     if exists(join(expanduser('~'), '.koji', 'config')):
         config.readfp(open(join(expanduser('~'), '.koji', 'config')))
     else:
         config.readfp(open('/etc/koji.conf'))
     cert = expanduser(config.get('koji', 'cert'))
     ca = expanduser(config.get('koji', 'ca'))
     serverca = expanduser(config.get('koji', 'serverca'))
     session = koji.ClientSession(config.get('koji', 'server'))
     if login:
         session.ssl_login(cert=cert, ca=ca, serverca=serverca)
     return session
Ejemplo n.º 3
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.
    '''

    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)
Ejemplo n.º 4
0
    def read(self, filename=None, priority=PRIO_DEFAULT):
        # :api
        if filename is None:
            filename = self._get_value('config_file_path')
        self._parser = ConfigParser()
        config_pp = dnf.conf.parser.ConfigPreProcessor(filename)
        try:
            self._parser.readfp(config_pp)
        except ParsingError as e:
            raise dnf.exceptions.ConfigError("Parsing file failed: %s" % 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)
Ejemplo n.º 5
0
    def read(self, filename=None):
        # :api
        if filename is None:
            filename = self.config_file_path
        parser = ConfigParser()
        config_pp = dnf.conf.parser.ConfigPreProcessor(filename)
        try:
            parser.readfp(config_pp)
        except ParsingError as e:
            raise dnf.exceptions.ConfigError("Parsing file failed: %s" % e)
        self.populate(parser, 'main')

        # update to where we read the file from
        self.config_file_path = filename
Ejemplo n.º 6
0
    def get_koji_session(self):
        """
        Return an authenticated koji session.

        Returns:
            koji.ClientSession: An intialized authenticated koji client.
        """
        config = ConfigParser()
        if os.path.exists(
                os.path.join(os.path.expanduser('~'), '.koji', 'config')):
            config.readfp(
                open(os.path.join(os.path.expanduser('~'), '.koji', 'config')))
        else:
            config.readfp(open('/etc/koji.conf'))
        session = koji.ClientSession(config.get('koji', 'server'))
        return session
Ejemplo n.º 7
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 as e:
        raise dnf.exceptions.ConfigError("Parsing file failed: %s" % e)
    ret = {}
    for section in parser.sections():
        ret[section] = VersionGroupConf()
        ret[section].populate(parser, section)
    return ret
Ejemplo n.º 8
0
 def get_yumex_config(self,configfile='.yumex.conf', sec='yumex' ):
     conf = YumexConf()
     parser = ConfigParser()    
     configfile=os.environ['HOME']+"/"+configfile
     if not os.path.exists(configfile):
         # if /etc/yumex.conf exists and is readable the copy it to homedir
         if os.path.exists('/etc/yumex.conf') and os.access("/etc/yumex.conf", os.R_OK):
             shutil.copyfile('/etc/yumex.conf', configfile)
     parser.read( configfile )
     if not parser.has_section('yumex'):
         parser.add_section('yumex')
     conf.populate( parser, sec )
     return conf
Ejemplo n.º 9
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.
    """

    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)
Ejemplo n.º 10
0
Archivo: conf.py Proyecto: rbuj/yumex
 def get_yumex_config(self, sec='yumex'):
     conf = YumexConf()
     parser = ConfigParser()
     self.logger.info("Using config file : "+CONF_FILE)
     if not os.path.exists(CONF_FILE):
         if os.path.exists(OLD_CONF_FILE):
             self.logger.info("Migrating settings from : "+OLD_CONF_FILE)
             shutil.move(OLD_CONF_FILE, CONF_FILE)
         # if /etc/yumex.conf exists and is readable the copy it to homedir
         elif os.path.exists('/etc/yumex.conf') and os.access("/etc/yumex.conf", os.R_OK):
             shutil.copyfile('/etc/yumex.conf', CONF_FILE)
     parser.read(CONF_FILE)
     if not parser.has_section('yumex'):
         parser.add_section('yumex')
     conf.populate(parser, sec)
     return conf
Ejemplo n.º 11
0
    def parse_file(self, input_file):
        """ Parse an update template file.

        :arg input_file: The filename of the update template.

        Returns an array of dictionaries of parsed update values which
        can be directly passed to the ``save`` method.

        """
        from iniparse.compat import ConfigParser
        self.log.info('Reading from %s ' % input_file)
        input_file = os.path.expanduser(input_file)
        if os.path.exists(input_file):
            defaults = {
                'type': 'bugfix',
                'request': 'testing',
                'notes': '',
                'bugs': '',
                'close_bugs': 'True',
                'autokarma': 'True',
                'stable_karma': 3,
                'unstable_karma': -3,
                'suggest_reboot': 'False',
            }
            config = ConfigParser(defaults)
            template_file = open(input_file)
            config.readfp(template_file)
            template_file.close()
            updates = []
            for section in config.sections():
                update = {}
                update['builds'] = section
                update['type_'] = config.get(section, 'type')
                update['request'] = config.get(section, 'request')
                update['bugs'] = config.get(section, 'bugs')
                update['close_bugs'] = config.getboolean(section, 'close_bugs')
                update['notes'] = config.get(section, 'notes')
                update['autokarma'] = config.getboolean(section, 'autokarma')
                update['stable_karma'] = config.getint(section, 'stable_karma')
                update['unstable_karma'] = config.getint(
                    section, 'unstable_karma')
                update['suggest_reboot'] = config.getboolean(
                    section, 'suggest_reboot')
                updates.append(update)
        return updates
Ejemplo n.º 12
0
    def parse_file(self, input_file):
        """ Parse an update template file.

        :arg input_file: The filename of the update template.

        Returns an array of dictionaries of parsed update values which
        can be directly passed to the ``save`` method.

        """
        from iniparse.compat import ConfigParser
        self.log.info(_('Reading from %s ') % input_file)
        input_file = expanduser(input_file)
        if exists(input_file):
            defaults = {
                'type': 'bugfix',
                'request': 'testing',
                'notes': '',
                'bugs': '',
                'close_bugs': 'True',
                'autokarma': 'True',
                'stable_karma': 3,
                'unstable_karma': -3,
                'suggest_reboot': 'False',
                }
            config = ConfigParser(defaults)
            template_file = open(input_file)
            config.readfp(template_file)
            template_file.close()
            updates = []
            for section in config.sections():
                update = {}
                update['builds'] = section
                update['type_'] = config.get(section, 'type')
                update['request'] = config.get(section, 'request')
                update['bugs'] = config.get(section, 'bugs')
                update['close_bugs'] = config.getboolean(section, 'close_bugs')
                update['notes'] = config.get(section, 'notes')
                update['autokarma'] = config.getboolean(section, 'autokarma')
                update['stable_karma'] = config.getint(section, 'stable_karma')
                update['unstable_karma'] = config.getint(section,
                                                         'unstable_karma')
                update['suggest_reboot'] = config.getboolean(section,
                                                             'suggest_reboot')
                updates.append(update)
        return updates