Esempio n. 1
0
def generate_triggers(domain):
    domain_settings = domain.settings
    yield env_update()

    d = {}
    for x in ("CONFIG_PROTECT", "CONFIG_PROTECT_MASK", "COLLISION_IGNORE",
              "INSTALL_MASK", "UNINSTALL_IGNORE"):
        d[x] = domain_settings.get(x, [])
        if isinstance(d[x], basestring):
            d[x] = d[x].split()

    yield ConfigProtectInstall(d["CONFIG_PROTECT"], d["CONFIG_PROTECT_MASK"])
    yield ConfigProtectUninstall()

    features = domain_settings.get("FEATURES", ())

    if "collision-protect" in features:
        yield CollisionProtect(d["CONFIG_PROTECT"], d["CONFIG_PROTECT_MASK"],
                               d["COLLISION_IGNORE"])

    if "protect-owned" in features and "collision-protect" not in features:
        yield ProtectOwned(domain.vdb, d["CONFIG_PROTECT"],
                           d["CONFIG_PROTECT_MASK"], d["COLLISION_IGNORE"])

    if "multilib-strict" in features:
        yield register_multilib_strict_trigger(domain_settings)

    if "sfperms" in features:
        yield SFPerms()

    yield install_into_symdir_protect(d["CONFIG_PROTECT"],
                                      d["CONFIG_PROTECT_MASK"])

    for x in ("man", "info", "doc"):
        if "no%s" % x in features:
            d["INSTALL_MASK"].append("/usr/share/%s" % x)
    l = []
    for x in d["INSTALL_MASK"]:
        x = x.rstrip("/")
        l.append(values.StrRegex(fnmatch.translate(x)))
        l.append(values.StrRegex(fnmatch.translate("%s/*" % x)))
    install_mask = l

    if install_mask:
        if len(install_mask) == 1:
            install_mask = install_mask[0]
        else:
            install_mask = values.OrRestriction(*install_mask)
        yield triggers.PruneFiles(install_mask.match)
        # note that if this wipes all /usr/share/ entries, should
        # wipe the empty dir.

    yield UninstallIgnore(d["UNINSTALL_IGNORE"])
    yield InfoRegen()
Esempio n. 2
0
    def trigger(self, engine, existing_cset, uninstall_cset):
        ignore = [values.StrRegex(fnmatch.translate(x), match=True)
                  for x in self.uninstall_ignore]
        ignore_filter = values.OrRestriction(*ignore).match

        remove = [x for x in existing_cset.iterfiles()
                  if ignore_filter(x.location)]
        for x in remove:
            del uninstall_cset[x]
Esempio n. 3
0
def convert_glob(token):
    if token in ('*', ''):
        return None
    elif '*' not in token:
        return values.StrExactMatch(token)
    elif not valid_globbing(token):
        raise ParseError("globs must be composed of [\w-.+], with optional "
                         "'*'- '%s' is disallowed however" % token)
    pattern = "^%s$" % (re.escape(token).replace("\*", ".*"), )
    return values.StrRegex(pattern, match=True)
Esempio n. 4
0
def parse_maintainer_name(value):
    """
    Case insensitive Regex match on the name bit of metadata.xml's
    maintainer data.
    """
    return packages.PackageRestriction(
        'maintainers',
        values.AnyMatch(
            values.GetAttrRestriction(
                'name', values.StrRegex(value.lower(), case_sensitive=False))))
Esempio n. 5
0
def parse_ownsre(value):
    """Value is a regexp matched against the string form of an fs object.

    This means the object kind is prepended to the path the regexp has
    to match.
    """
    return packages.PackageRestriction(
        'contents',
        values.AnyMatch(
            values.GetAttrRestriction('location', values.StrRegex(value))))
Esempio n. 6
0
def parse_maintainer(value):
    """
    Case insensitive Regex match on the combined 'name <email>' bit of
    metadata.xml's maintainer data.
    """
    return packages.PackageRestriction(
        'maintainers',
        values.AnyMatch(
            values.UnicodeConversion(
                values.StrRegex(value.lower(), case_sensitive=False))))
Esempio n. 7
0
def convert_glob(token):
    if token in ('*', ''):
        return None
    elif '*' not in token:
        return values.StrExactMatch(token)
    elif not valid_globbing(token):
        raise ParseError("globs must be composed of [\\w-.+], with optional "
                         f"'*'- {token!r} is disallowed however")
    pattern = re.escape(token).replace('\\*', '.*')
    pattern = f"^{pattern}$"
    return values.StrRegex(pattern, match=True)
Esempio n. 8
0
def gen_collision_ignore_filter(offset, extra_ignores=()):
    collapsed_d, inc, colon = collapse_envd(pjoin(offset, "etc/env.d"))
    ignored = collapsed_d.setdefault("COLLISION_IGNORE", [])
    ignored.extend(extra_ignores)
    ignored.extend(["*/.keep", "*/.keep_*"])

    ignored = stable_unique(ignored)
    for i, x in enumerate(ignored):
        if not x.endswith("/*") and os.path.isdir(x):
            ignored[i] = ignored.rstrip("/") + "/*"
    ignored = [values.StrRegex(fnmatch.translate(x))
               for x in stable_unique(ignored)]
    if len(ignored) == 1:
        return ignored[0]
    return values.OrRestriction(*ignored)
Esempio n. 9
0
def parse_maintainer(value):
    """
    Case insensitive Regex match on the combined 'name <email>' bit of
    metadata.xml's maintainer data.
    """
    if value:
        return packages.PackageRestriction(
            'maintainers',
            values.AnyMatch(
                values.UnicodeConversion(
                    values.StrRegex(value.lower(), case_sensitive=False))))
    else:
        # empty string matches packages without a maintainer
        return packages.PackageRestriction('maintainers',
                                           values.EqualityMatch(()))
Esempio n. 10
0
    def trigger(self, engine, existing_cset, uninstall_cset, old_cset={}):
        ignore = [
            values.StrRegex(fnmatch.translate(x), match=True)
            for x in self.uninstall_ignore
        ]
        ignore_filter = values.OrRestriction(*ignore).match

        remove = [
            x for x in existing_cset.iterfiles() if ignore_filter(x.location)
        ]
        for x in remove:
            # don't remove matching files being uninstalled
            del uninstall_cset[x]
            # don't remove matching files being replaced
            old_cset.discard(x)
Esempio n. 11
0
    def __iter__(self):
        yield env_update()

        yield ConfigProtectInstall(
            self.opts["CONFIG_PROTECT"], self.opts["CONFIG_PROTECT_MASK"])
        yield ConfigProtectUninstall()

        if "collision-protect" in self.domain.features:
            yield CollisionProtect(
                self.opts["CONFIG_PROTECT"], self.opts["CONFIG_PROTECT_MASK"],
                self.opts["COLLISION_IGNORE"])

        if "protect-owned" in self.domain.features and "collision-protect" not in self.domain.features:
            yield ProtectOwned(
                self.domain.installed_repos, self.opts["CONFIG_PROTECT"],
                self.opts["CONFIG_PROTECT_MASK"], self.opts["COLLISION_IGNORE"])

        if "multilib-strict" in self.domain.features:
            yield register_multilib_strict_trigger(self.opts)

        if "sfperms" in self.domain.features:
            yield SFPerms()

        yield install_into_symdir_protect(
            self.opts["CONFIG_PROTECT"], self.opts["CONFIG_PROTECT_MASK"])

        # TODO: support multiple binpkg repo targets?
        pkgdir = self.opts.get("PKGDIR", None)
        if pkgdir:
            target_repo = self.domain.binary_repos_raw.get(pkgdir, None)
        else:
            # get the highest priority binpkg repo
            try:
                target_repo = self.domain.binary_repos_raw[0]
            except IndexError:
                target_repo = None
        if target_repo is not None:
            if 'buildpkg' in self.domain.features:
                yield triggers.SavePkg(pristine='no', target_repo=target_repo)
            elif 'pristine-buildpkg' in self.domain.features:
                yield triggers.SavePkg(pristine='yes', target_repo=target_repo)
            elif 'buildsyspkg' in self.domain.features:
                yield triggers.SavePkgIfInPkgset(
                    pristine='yes', target_repo=target_repo, pkgset=self.domain.profile.system)
            elif 'unmerge-backup' in self.domain.features:
                yield triggers.SavePkgUnmerging(target_repo=target_repo)

        if 'save-deb' in self.domain.features:
            path = self.opts.get("DEB_REPO_ROOT", None)
            if path is None:
                logger.warning("disabling save-deb; DEB_REPO_ROOT is unset")
            else:
                yield ospkg.triggers.SaveDeb(
                    basepath=normpath(path), maintainer=self.opts.get("DEB_MAINAINER", ''),
                    platform=self.opts.get("DEB_ARCHITECTURE", ""))

        if 'splitdebug' in self.domain.features:
            yield triggers.BinaryDebug(mode='split', compress=('compressdebug' in self.domain.features))
        elif 'strip' in self.domain.features or 'nostrip' not in self.domain.features:
            yield triggers.BinaryDebug(mode='strip')

        if '-fixlafiles' not in self.domain.features:
            yield libtool.FixLibtoolArchivesTrigger()

        for x in ("man", "info", "doc"):
            if f"no{x}" in self.domain.features:
                self.opts["INSTALL_MASK"].append(f"/usr/share/{x}")
        l = []
        for x in self.opts["INSTALL_MASK"]:
            x = x.rstrip("/")
            l.append(values.StrRegex(fnmatch.translate(x)))
            l.append(values.StrRegex(fnmatch.translate(f"{x}/*")))
        install_mask = l

        if install_mask:
            if len(install_mask) == 1:
                install_mask = install_mask[0]
            else:
                install_mask = values.OrRestriction(*install_mask)
            yield triggers.PruneFiles(install_mask.match)
            # note that if this wipes all /usr/share/ entries, should
            # wipe the empty dir.

        yield UninstallIgnore(self.opts["UNINSTALL_IGNORE"])
        yield InfoRegen()
Esempio n. 12
0
def parse_envmatch(value):
    """Apply a regexp to the environment."""
    return packages.PackageRestriction(
        'environment',
        DataSourceRestriction(values.AnyMatch(values.StrRegex(value))))
Esempio n. 13
0
def parse_description(value):
    """Value is used as a regexp matching description or longdescription."""
    matcher = values.StrRegex(value, case_sensitive=False)
    return packages.OrRestriction(*list(
        packages.PackageRestriction(attr, matcher)
        for attr in ('description', 'longdescription')))
Esempio n. 14
0
def mk_strregex(value, **kwds):
    try:
        return values.StrRegex(value, **kwds)
    except re.error as e:
        raise ValueError("invalid regex: %r, %s" % (value, e))