Пример #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,
                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))
Пример #2
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))
Пример #3
0
def mk_config(*args, **kwds):
    return central.CompatConfigManager(central.ConfigManager(*args, **kwds))
Пример #4
0
 def _mk_config(self, *args, **kwds):
     config = central.ConfigManager(*args, **kwds)
     if self.requires_compat_config_manager:
         config = central.CompatConfigManager(config)
     return config