How to use the pkgcore.restrictions.packages.AndRestriction 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 / repository / test_prototype.py View on Github external
"category", values.StrExactMatch("dev-util"))
        self.assertEqual(
            sorted(set(x.package for x in self.repo.itermatch(rc))),
            sorted(["diffball", "bsdiff"]))
        rp = packages.PackageRestriction(
            "package", values.StrExactMatch("diffball"))
        self.assertEqual(
            list(x.version for x in self.repo.itermatch(rp, sorter=sorted)),
            ["0.7", "1.0"])
        self.assertEqual(
            self.repo.match(packages.OrRestriction(rc, rp), sorter=sorted),
            sorted(VersionedCPV(x) for x in (
                "dev-util/diffball-0.7", "dev-util/diffball-1.0",
                "dev-util/bsdiff-0.4.1", "dev-util/bsdiff-0.4.2")))
        self.assertEqual(
            sorted(self.repo.itermatch(packages.AndRestriction(rc, rp))),
            sorted(VersionedCPV(x) for x in (
                "dev-util/diffball-0.7", "dev-util/diffball-1.0")))
        self.assertEqual(
            sorted(self.repo),
            self.repo.match(packages.AlwaysTrue, sorter=sorted))
        # mix/match cat/pkg to check that it handles that corner case
        # properly for sorting.
        self.assertEqual(
            sorted(self.repo, reverse=True),
            self.repo.match(packages.OrRestriction(
                rc, rp, packages.AlwaysTrue),
                sorter=partial(sorted, reverse=True)))
        rc2 = packages.PackageRestriction(
            "category", values.StrExactMatch("dev-lib"))
        self.assertEqual(
            sorted(self.repo.itermatch(packages.AndRestriction(rp, rc2))),
github pkgcore / pkgcore / pkgcore / graph / resolver.py View on Github external
debug("  blocker %s would block previous choices of %s" % (a, conflicts))
						cur = self.current_stack
						self.atoms[a] = (choice_point(a, []), [t])
						self.unsatisfiable_atom(a, "backtracking for blocker", False)
						cur.pop(-1)
					else:
						debug("   blocker %s refed for %s" % (a, self.current_stack[-2]))
						# ref it.
						self.atoms[a] = [choice_point(a, []), []]
						self.ref_stack_for_atom(a, t)
						self.current_stack.pop(-1)
				elif a in self.current_stack[:-1]:
					# cycle ask the repo for a pkg configuration that breaks the cycle.
					debug("   cycle detected for %s: stack %s" % (a, self.current_stack))
					v = values.ContainmentMatch(a, negate=True)
					yield packages.AndRestriction(a,
						packages.PackageRestriction("depends", v), packages.PackageRestriction("rdepends", v))
				else:
					debug("   yielding %s for %s" % (a, self.current_stack))
					yield a
			else:
				# all satisfied.
				self.current_stack.pop(-1)

			try:
				assert not any(x.blocks for x in self.current_stack)
			except AssertionError:
				import pdb;pdb.set_trace()
				raise

		# sanity check.  all nodes in the graph *should* have solutions.
		# no exceptions, solutions are valid.
github pkgcore / pkgcore / src / pkgcore / ebuild / domain.py View on Github external
def generate_filter(masks, unmasks, *extra):
    # note that we ignore unmasking if masking isn't specified.
    # no point, mainly
    masking = make_mask_filter(masks, negate=True)
    unmasking = make_mask_filter(unmasks, negate=False)
    r = ()
    if masking:
        if unmasking:
            r = (packages.OrRestriction(masking, unmasking, disable_inst_caching=True),)
        else:
            r = (masking,)
    return packages.AndRestriction(disable_inst_caching=True, finalize=True, *(r + extra))
github pkgcore / pkgcore / pkgcore / scripts / pquery.py View on Github external
def _parse_and(tokens):
            return packages.AndRestriction(*tokens)
        andcall.setParseAction(_parse_and)
github pkgcore / pkgcore / src / pkgcore / util / parserestrict.py View on Github external
r = list(map(convert_glob, tsplit))
    if not r[0] and not r[1]:
        restrictions.append(packages.AlwaysTrue)
    elif not r[0]:
        restrictions.append(packages.PackageRestriction("package", r[1]))
    elif not r[1]:
        restrictions.append(packages.PackageRestriction("category", r[0]))
    else:
        restrictions.extend((
            packages.PackageRestriction("category", r[0]),
            packages.PackageRestriction("package", r[1]),
        ))
    if len(restrictions) == 1:
        return restrictions[0]
    return packages.AndRestriction(*restrictions)
github pkgcore / pkgcore / src / pkgcore / ebuild / atom.py View on Github external
def convert_to_conditionals(self):
        static_use = [use for use in self.use if use[-1] not in '?=']
        variable = [use for use in self.use if use[-1] in '?=']
        return PkgAndRestriction(
            *self._recurse_transitive_use_conds(
                self._stripped_use(), static_use, variable))
github pkgcore / pkgcore / pkgcore / scripts / pquery.py View on Github external
val = getattr(options, attr)
        if len(val) == 1:
            # Omit the boolean.
            restrict.append(val[0])
        elif val:
            restrict.append(packages.OrRestriction(finalize=True, *val))

    if not restrict:
        # Match everything in the repo.
        restrict = packages.AlwaysTrue
    elif len(restrict) == 1:
        # Single restriction, omit the AndRestriction for a bit of speed
        restrict = restrict[0]
    else:
        # "And" them all together
        restrict = packages.AndRestriction(finalize=True, *restrict)

    if options.debug:
        for repo in repos:
            out.write('repo: %r' % (repo,))
        out.write('restrict: %r' % (restrict,))
        out.write()

    # Run the query
    for repo in repos:
        try:
            for pkgs in pkgutils.groupby_pkg(
                repo.itermatch(restrict, sorter=sorted)):
                pkgs = list(pkgs)
                if options.noversion:
                    print_packages_noversion(options, out, err, pkgs, vdbs)
                elif options.min or options.max:
github pkgcore / pkgcore / src / pkgcore / pkgsets / glsa.py View on Github external
# this is a non-range.
                    raise ValueError(
                        "range %s version %s is a guaranteed empty set" %
                        (op, str(node.text.strip())))
                elif op == "rle": # rle -r0 -> = -r0
                    return atom_restricts.VersionMatch("=", base.version, negate=negate)
                elif op == "rge": # rge -r0 -> ~
                    return atom_restricts.VersionMatch("~", base.version, negate=negate)
            # rgt -r0 passes through to regular ~ + >
            restrictions.append(atom_restricts.VersionMatch("~", base.version))
        restrictions.append(
            atom_restricts.VersionMatch(restrict, base.version, rev=base.revision),
        )
        if slot:
            restrictions.append(atom_restricts.SlotDep(slot))
        return packages.AndRestriction(*restrictions, negate=negate)
github pkgcore / pkgcore / src / pkgcore / ebuild / resolver.py View on Github external
if nodeps:
        vdbs = list(map(misc.nodeps_repo, vdbs))
        dbs = list(map(misc.nodeps_repo, dbs))
    elif not verify_vdb:
        vdbs = list(map(misc.nodeps_repo, vdbs))
        dbs = list(dbs)

    if force_replace:
        resolver_cls = generate_replace_resolver_kls(resolver_cls)
    return resolver_cls(vdbs + dbs, plan.pkg_sort_highest,
                        plan.merge_plan.prefer_reuse_strategy, **kwds)

_vdb_restrict = packages.OrRestriction(
    packages.PackageRestriction("repo.livefs", values.EqualityMatch(False)),
    packages.AndRestriction(
        packages.PackageRestriction(
            "category", values.StrExactMatch("virtual")),
        packages.PackageRestriction(
            "package_is_real", values.EqualityMatch(False)),
        ),
    )


class empty_tree_merge_plan(plan.merge_plan):

    _vdb_restriction = _vdb_restrict

    def __init__(self, dbs, *args, **kwds):
        """
        :param args: see :obj:`pkgcore.resolver.plan.merge_plan.__init__`
            for valid args