How to use the pkgcore.config.basics function in pkgcore

To help you get started, we’ve selected a few pkgcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pkgcore / pkgcore / tests / module / scripts / test_pclonecache.py View on Github external
def test_parser(self):
        self.assertError(
            'the following arguments are required: target',
            'spork')
        self.assertError(
            "argument source: couldn't find cache 'spork'",
            'spork', 'spork2')
        self.assertError(
            "argument target: couldn't find cache 'spork2' (available: spork)",
            'spork', 'spork2',
            spork=basics.HardCodedConfigSection({'class': Cache}))
        self.assertError(
            "argument target: cache 'spork2' is readonly",
            'spork', 'spork2',
            spork=basics.HardCodedConfigSection({'class': Cache,}),
            spork2=basics.HardCodedConfigSection({'class': Cache,}))
github pkgcore / pkgcore / tests / module / config / test_init.py View on Github external
def test_load_config(self):
        manager = load_config(user_conf_file=self.user_config.name)
        self.assertEqual(manager.foo['foo'], ((), {}))

        # Test user config overrides system config.
        manager = load_config(
            user_conf_file=self.user_config.name,
            system_conf_file=self.system_config.name)
        self.assertEqual(manager.foo['foo'], ((), {}))

        # Test prepends.
        manager = load_config(
            user_conf_file=self.user_config.name,
            prepend_sources=[{'myfoo': basics.HardCodedConfigSection({
                            'inherit': ['foo']})}])
        self.assertEqual(manager.foo['myfoo'], ((), {}))

        # Test disabling loading.
        manager = load_config(
            user_conf_file=self.user_config.name,
            skip_config_files=True)
        self.assertRaises(
            KeyError,
            operator.getitem, manager.foo, 'foo')
github pkgcore / pkgcore / tests / scripts / test_pquery.py View on Github external
object.__init__(self)
        self.source_repos = repos
        self.installed_repos = vdb


@configurable(typename='repo')
def fake_repo():
    return util.SimpleTree({'spork': {'foon': ('1', '2')}})


@configurable(typename='repo')
def fake_vdb():
    return util.SimpleTree({})


domain_config = basics.HardCodedConfigSection({
        'class': FakeDomain,
        'repos': [basics.HardCodedConfigSection({'class': fake_repo})],
        'vdb': [basics.HardCodedConfigSection({'class': fake_vdb})],
        'default': True,
        })


class CommandlineTest(TestCase, ArgParseMixin):

    _argparser = pquery.argparser

    def test_parser(self):
        self.assertError(
            'argument --min: not allowed with argument --max',
            '--max', '--min')
        self.parse('--all', domain=domain_config)
github pkgcore / pkgcore / tests / module / config / test_basics.py View on Github external
def test_alias(self):
        def spoon():
            """Noop."""
        foon = central.CollapsedConfig(basics.ConfigType(spoon), {}, None)
        class MockManager:
            def collapse_named_section(self, name):
                if name == 'foon':
                    return foon
                return object()
        manager = MockManager()
        alias = basics.section_alias('foon', 'spoon')
        type_obj = basics.ConfigType(alias.render_value(manager, 'class',
                                                     'callable'))
        self.assertEqual('spoon', type_obj.name)
        self.assertIdentical(
            foon,
            alias.render_value(manager, 'target', 'ref:spoon').collapse())
github pkgcore / pkgcore / tests / scripts / test_pclonecache.py View on Github external
def test_parser(self):
        self.assertError(
            'the following arguments are required: target',
            'spork')
        self.assertError(
            "argument source: couldn't find cache 'spork'",
            'spork', 'spork2')
        self.assertError(
            "argument target: couldn't find cache 'spork2' (available: spork)",
            'spork', 'spork2',
            spork=basics.HardCodedConfigSection({'class': Cache}))
        self.assertError(
            "argument target: cache 'spork2' is readonly",
            'spork', 'spork2',
            spork=basics.HardCodedConfigSection({'class': Cache,}),
            spork2=basics.HardCodedConfigSection({'class': Cache,}))
github pkgcore / pkgcore / src / pkgcore / ebuild / portage_conf.py View on Github external
def my_convert_hybrid(manager, val, arg_type):
    """Modified convert_hybrid using a sequence of strings for section_refs."""
    if arg_type.startswith('refs:'):
        subtype = 'ref:' + arg_type.split(':', 1)[1]
        return [basics.LazyNamedSectionRef(manager, subtype, name) for name in val]
    return basics.convert_hybrid(manager, val, arg_type)
github pkgcore / pkgcore / src / pkgcore / scripts / pconfig.py View on Github external
def describe_class_main(options, out, err):
    """Describe the arguments a class needs."""
    try:
        type_obj = basics.ConfigType(options.target_class)
    except errors.TypeDefinitionError:
        err.write('Not a valid type!')
        return 1
    write_type(out, type_obj)
github pkgcore / pkgcore / src / pkgcore / config / central.py View on Github external
def _compat_mangle_config(self, config):
        if hasattr(config, 'sections'):
            return config
        return basics.GeneratedConfigSource(config, "unknown")
github pkgcore / pkgcore / src / pkgcore / config / dhcpformat.py View on Github external
_section_contents = pyp.dictOf(
    _value, pyp.Group(pyp.OneOrMore(_value | _section)) + pyp.Suppress(';'))

# "statement seems to have no effect"
# pylint: disable-msg=W0104
_section << pyp.Group(pyp.Suppress('{') + _section_contents +
                      pyp.Suppress('}'))

parser = (
    pyp.stringStart +
    pyp.dictOf(_value, _section).ignore(pyp.pythonStyleComment) +
    pyp.stringEnd)


class ConfigSection(basics.ConfigSection):
    """Expose a section_contents from pyparsing as a ConfigSection.

    mke2fsformat also uses this.
    """

    def __init__(self, section):
        super().__init__()
        self.section = section

    def __contains__(self, name):
        return name in self.section

    def keys(self):
        return list(self.section.keys())

    def render_value(self, central, name, arg_type):
github pkgcore / pkgcore / pkgcore / plugins / pkgcore_configurables.py View on Github external
from pkgcore.config import basics
from pkgcore.ebuild import (
    portage_conf, repository as ebuild_repo, profiles, domain, eclass_cache,
    overlay_repository, formatter)
from pkgcore.pkgsets import system, filelist, installed, glsa
from pkgcore.vdb import ondisk
from pkgcore.cache import flat_hash, metadata
from pkgcore.fetch import custom
from pkgcore.binpkg import repository as binpkg_repo
from pkgcore.sync import rsync, base


pkgcore_plugins = {
    'configurable': [
        basics.section_alias,
        basics.parse_config_file,
        portage_conf.SecurityUpgradesViaProfile,
        portage_conf.config_from_make_conf,
        system.SystemSet,
        ondisk.tree,
        flat_hash.database,
        metadata.database,
        metadata.paludis_flat_list,
        custom.fetcher,
        binpkg_repo.tree,
        ebuild_repo.UnconfiguredTree,
        ebuild_repo.SlavedTree,
        profiles.OnDiskProfile,
        domain.domain,
        eclass_cache.cache,
        eclass_cache.StackedCaches,