Пример #1
0
def load_config(user_conf_file=USER_CONF_FILE,
                system_conf_file=SYSTEM_CONF_FILE,
                debug=False, prepend_sources=(), append_sources=(), skip_config_files=False):
    """
    the main entry point for any code looking to use pkgcore.

    :param user_conf_file: file to attempt to load, else defaults to trying to
        load portage 2 style configs (/etc/make.conf, /etc/make.profile)

    :return: :obj:`pkgcore.config.central.ConfigManager` instance
        representing the system config.
    """

    from pkgcore.config import central, cparser
    from pkgcore.plugin import get_plugins
    import os

    configs = list(prepend_sources)
    configs.extend(get_plugins('global_config'))
    if not skip_config_files:
        have_system_conf = os.path.isfile(system_conf_file)
        have_user_conf = os.path.isfile(user_conf_file)
        if have_system_conf or have_user_conf:
            if have_system_conf:
                configs.append(
                    cparser.config_from_file(open(system_conf_file)))
            if have_user_conf:
                configs.append(cparser.config_from_file(open(user_conf_file)))
        else:
            # make.conf...
            from pkgcore.ebuild.portage_conf import config_from_make_conf
            configs.append(config_from_make_conf())
    configs.extend(append_sources)
    return central.CompatConfigManager(central.ConfigManager(configs, debug=debug))
Пример #2
0
def load_config(user_conf_file=USER_CONF_FILE,
                system_conf_file=SYSTEM_CONF_FILE,
                debug=False,
                prepend_sources=(),
                append_sources=(),
                skip_config_files=False,
                profile_override=None,
                location='/etc/'):
    """
    the main entry point for any code looking to use pkgcore.

    :param user_conf_file: file to attempt to load, else defaults to trying to
        load portage 2 style configs (/etc/portage/make.conf and
        /etc/portage/make.profile or the deprecated /etc/make.conf and
        /etc/make.profile locations)
    :param location: location the portage configuration is based in,
        defaults to /etc
    :param profile_override: profile to use instead of the current system
        profile, i.e. the target path of the /etc/portage/make.profile
        (or deprecated /etc/make.profile) symlink

    :return: :obj:`pkgcore.config.central.ConfigManager` instance
        representing the system config.
    """

    from pkgcore.config import central, cparser
    from pkgcore.plugin import get_plugins
    import os

    configs = list(prepend_sources)
    configs.extend(get_plugins('global_config'))
    if not skip_config_files:
        have_system_conf = os.path.isfile(system_conf_file)
        have_user_conf = os.path.isfile(user_conf_file)
        if have_system_conf or have_user_conf:
            if have_system_conf:
                with open(system_conf_file) as f:
                    configs.append(cparser.config_from_file(f))
            if have_user_conf:
                with open(user_conf_file) as f:
                    configs.append(cparser.config_from_file(f))
        else:
            # make.conf...
            from pkgcore.ebuild.portage_conf import config_from_make_conf
            configs.append(
                config_from_make_conf(location=location,
                                      profile_override=profile_override))
    configs.extend(append_sources)
    return central.CompatConfigManager(
        central.ConfigManager(configs, debug=debug))
Пример #3
0
def load_config(user_conf_file=USER_CONF_FILE,
                system_conf_file=SYSTEM_CONF_FILE,
                debug=False, prepend_sources=(), append_sources=(),
                skip_config_files=False, profile_override=None,
                location='/etc/'):
    """
    the main entry point for any code looking to use pkgcore.

    :param user_conf_file: file to attempt to load, else defaults to trying to
        load portage 2 style configs (/etc/portage/make.conf and
        /etc/portage/make.profile or the deprecated /etc/make.conf and
        /etc/make.profile locations)
    :param location: location the portage configuration is based in,
        defaults to /etc
    :param profile_override: profile to use instead of the current system
        profile, i.e. the target path of the /etc/portage/make.profile
        (or deprecated /etc/make.profile) symlink

    :return: :obj:`pkgcore.config.central.ConfigManager` instance
        representing the system config.
    """

    from pkgcore.config import central, cparser
    from pkgcore.plugin import get_plugins
    import os

    configs = list(prepend_sources)
    configs.extend(get_plugins('global_config'))
    if not skip_config_files:
        have_system_conf = os.path.isfile(system_conf_file)
        have_user_conf = os.path.isfile(user_conf_file)
        if have_system_conf or have_user_conf:
            if have_system_conf:
                with open(system_conf_file) as f:
                    configs.append(cparser.config_from_file(f))
            if have_user_conf:
                with open(user_conf_file) as f:
                    configs.append(cparser.config_from_file(f))
        else:
            # make.conf...
            from pkgcore.ebuild.portage_conf import config_from_make_conf
            configs.append(config_from_make_conf(
                location=location, profile_override=profile_override))
    configs.extend(append_sources)
    return central.CompatConfigManager(central.ConfigManager(configs, debug=debug))
Пример #4
0
    def test_missing_section_ref(self):
        config = cparser.config_from_file(StringIO('''
[test]
ref = 'missing'
'''))
        section = config['test']
        self.assertRaises(
            errors.ConfigurationError,
            section.render_value(
                central.ConfigManager([]), 'ref', 'ref:drawer').collapse)
Пример #5
0
    def test_missing_section_ref(self):
        config = cparser.config_from_file(
            StringIO('''
[test]
ref = 'missing'
'''))
        section = config['test']
        self.assertRaises(
            errors.ConfigurationError,
            section.render_value(central.ConfigManager([]), 'ref',
                                 'ref:drawer').collapse)
Пример #6
0
    def test_config_from_ini(self):
        config = cparser.config_from_file(StringIO('''
[test]
string = 'hi I am a string'
list = foo bar baz
list.prepend = pre bits
list.append = post bits
true = yes
false = no
'''))
        self.assertEqual(config.keys(), ['test'])
        section = config['test']
        for key, arg_type, value in [
            ('string', 'str', [None, 'hi I am a string', None]),
            ('list', 'list', [
                    ['pre', 'bits'], ['foo', 'bar', 'baz'], ['post', 'bits']]),
            ('true', 'bool', True),
            ('false', 'bool', False),
            ]:
            self.assertEqual(section.render_value(None, key, arg_type), value)
Пример #7
0
    def test_config_from_ini(self):
        config = cparser.config_from_file(
            StringIO('''
[test]
string = 'hi I am a string'
list = foo bar baz
list.prepend = pre bits
list.append = post bits
true = yes
false = no
'''))
        self.assertEqual(config.keys(), ['test'])
        section = config['test']
        for key, arg_type, value in [
            ('string', 'str', [None, 'hi I am a string', None]),
            ('list', 'list', [['pre', 'bits'], ['foo', 'bar', 'baz'],
                              ['post', 'bits']]),
            ('true', 'bool', True),
            ('false', 'bool', False),
        ]:
            self.assertEqual(section.render_value(None, key, arg_type), value)
Пример #8
0
def load_config(user_conf_file=const.USER_CONF_FILE,
                system_conf_file=const.SYSTEM_CONF_FILE,
                debug=False,
                prepend_sources=(),
                append_sources=(),
                skip_config_files=False,
                profile_override=None,
                location=None,
                **kwargs):
    """The main entry point for any code looking to use pkgcore.

    Args:
        user_conf_file (optional[str]): pkgcore user config file path
        system_conf_file (optional[str]): system pkgcore config file path
        profile_override (optional[str]): targeted profile instead of system setting
        location (optional[str]): path to pkgcore config file or portage config directory
        skip_config_files (optional[str]): don't attempt to load any config files

    Returns:
        :obj:`pkgcore.config.central.ConfigManager` instance: system config
    """
    configs = list(prepend_sources)
    if not skip_config_files:
        # load a pkgcore config file if one exists
        for config in (location, user_conf_file, system_conf_file):
            if config is not None and os.path.isfile(config):
                with open(config) as f:
                    configs.append(cparser.config_from_file(f))
                break
        # otherwise load the portage config
        else:
            # delay importing to avoid circular imports
            from pkgcore.ebuild.portage_conf import PortageConfig
            configs.append(
                PortageConfig(location=location,
                              profile_override=profile_override,
                              **kwargs))
    configs.extend(append_sources)
    return central.CompatConfigManager(
        central.ConfigManager(configs, debug=debug))