Пример #1
0
def gen_config_protect_filter(offset, extra_protects=(), extra_disables=()):
    collapsed_d, inc, colon = collapse_envd(pjoin(offset, "etc/env.d"))
    collapsed_d.setdefault("CONFIG_PROTECT", []).extend(extra_protects)
    collapsed_d.setdefault("CONFIG_PROTECT_MASK", []).extend(extra_disables)

    r = [
        values.StrGlobMatch(normpath(x).rstrip("/") + "/")
        for x in set(stable_unique(collapsed_d["CONFIG_PROTECT"] + ["/etc"]))
    ]
    if len(r) > 1:
        r = values.OrRestriction(*r)
    else:
        r = r[0]
    neg = stable_unique(collapsed_d["CONFIG_PROTECT_MASK"])
    if neg:
        if len(neg) == 1:
            r2 = values.StrGlobMatch(normpath(neg[0]).rstrip("/") + "/",
                                     negate=True)
        else:
            r2 = values.OrRestriction(
                negate=True,
                *[
                    values.StrGlobMatch(normpath(x).rstrip("/") + "/")
                    for x in set(neg)
                ])
        r = values.AndRestriction(r, r2)
    return r
Пример #2
0
 def generate_restrict_from_range(self, node, negate=False):
     op = str(node.get("range").strip())
     base = str(node.text.strip())
     glob = base.endswith("*")
     if glob:
         base = base[:-1]
     base = cpv.versioned_CPV("cat/pkg-%s" % base)
     restrict = self.op_translate[op.lstrip("r")]
     if op.startswith("r"):
         if glob:
             raise ValueError("glob cannot be used with %s ops" % op)
         elif not base.revision:
             if '=' not in restrict:
                 # this is a non-range.
                 raise ValueError(
                     "range %s version %s is a guaranteed empty set" %
                     (op, str(node.text.strip())))
             return atom_restricts.VersionMatch("~",
                                                base.version,
                                                negate=negate)
         return packages.AndRestriction(
             atom_restricts.VersionMatch("~", base.version),
             atom_restricts.VersionMatch(restrict,
                                         base.version,
                                         rev=base.revision),
             negate=negate)
     if glob:
         return packages.PackageRestriction(
             "fullver", values.StrGlobMatch(base.fullver))
     return atom_restricts.VersionMatch(restrict,
                                        base.version,
                                        rev=base.revision,
                                        negate=negate)
Пример #3
0
 def generate_restrict_from_range(self, node, negate=False):
     op = str(node.get("range").strip())
     base = str(node.text.strip())
     glob = base.endswith("*")
     if glob:
         base = base[:-1]
     base = cpv.versioned_CPV("cat/pkg-%s" % base)
     restrict = self.op_translate[op.lstrip("r")]
     if glob:
         if op != "eq":
             raise ValueError("glob cannot be used with %s ops" % op)
         return packages.PackageRestriction(
             "fullver", values.StrGlobMatch(base.fullver))
     if op.startswith("r"):
         if not base.revision:
             if op == "rlt": # rlt -r0 can never match
                 # 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 ~ + >
         return packages.AndRestriction(
             atom_restricts.VersionMatch("~", base.version),
             atom_restricts.VersionMatch(restrict, base.version, rev=base.revision),
             negate=negate)
     return atom_restricts.VersionMatch(
         restrict, base.version, rev=base.revision, negate=negate)
Пример #4
0
    def restrictions(self):
        # ordering here matters; against 24702 ebuilds for
        # a non matchable atom with package as the first restriction
        # 10 loops, best of 3: 206 msec per loop
        # with category as the first(the obvious ordering)
        # 10 loops, best of 3: 209 msec per loop
        # why?  because category is more likely to collide;
        # at the time of this profiling, there were 151 categories.
        # over 11k packages however.
        r = [restricts.PackageDep(self.package), restricts.CategoryDep(self.category)]

        if self.repo_id is not None:
            r.insert(0, restricts.RepositoryDep(self.repo_id))

        if self.fullver is not None:
            if self.op == '=*':
                r.append(packages.PackageRestriction(
                    "fullver", values.StrGlobMatch(self.fullver)))
            else:
                r.append(restricts.VersionMatch(
                    self.op, self.version, self.revision, negate=self.negate_vers))

        if self.slot is not None:
            r.append(restricts.SlotDep(self.slot))
            if self.subslot is not None:
                r.append(restricts.SubSlotDep(self.subslot))

        if self.use is not None:
            r.extend(restricts._parse_nontransitive_use(self.use))

        return tuple(r)
Пример #5
0
    def generate_restrict_from_range(self, node, negate=False):
        op = str(node.get("range").strip())
        slot = str(node.get("slot", "").strip())

        try:
            restrict = self.op_translate[op.lstrip("r")]
        except KeyError:
            raise ValueError(f'unknown operator: {op!r}')
        if node.text is None:
            raise ValueError(f"{op!r} node missing version")

        base = str(node.text.strip())
        glob = base.endswith("*")
        if glob:
            base = base[:-1]
        base = cpv.VersionedCPV(f"cat/pkg-{base}")

        if glob:
            if op != "eq":
                raise ValueError(f"glob cannot be used with {op} ops")
            return packages.PackageRestriction(
                "fullver", values.StrGlobMatch(base.fullver))
        restrictions = []
        if op.startswith("r"):
            if not base.revision:
                if op == "rlt":  # rlt -r0 can never match
                    # 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)