Example #1
0
class nodeps_repo(object):

    """
    repository wrapper that returns wrapped pkgs via
    :obj:`MutatedPkg` that have their depends/rdepends/post_rdepends wiped
    """

    default_depends = default_rdepends = default_post_rdepends = DepSet()

    def __init__(self, repo):
        """
        :param repo: repository to wrap
        """
        self.raw_repo = repo

    def itermatch(self, *a, **kwds):
        return (MutatedPkg(
            x, overrides={"depends": self.default_depends,
                          "rdepends": self.default_rdepends,
                          "post_rdepends": self.default_post_rdepends}
            )
            for x in self.raw_repo.itermatch(*a, **kwds))

    def match(self, *a, **kwds):
        return list(self.itermatch(*a, **kwds))

    __getattr__ = GetAttrProxy("raw_repo")

    def __iter__(self):
        return self.itermatch(packages.AlwaysTrue)
Example #2
0
class nodeps_repo:
    """Repository wrapper that returns wrapped pkgs with deps wiped."""

    default_bdepend = default_depend = default_rdepend = default_pdepend = DepSet(
    )

    def __init__(self, repo):
        """
        :param repo: repository to wrap
        """
        self.raw_repo = repo

    def itermatch(self, *a, **kwds):
        return (MutatedPkg(x,
                           overrides={
                               "bdepend": self.default_bdepend,
                               "depend": self.default_depend,
                               "rdepend": self.default_rdepend,
                               "pdepend": self.default_pdepend
                           }) for x in self.raw_repo.itermatch(*a, **kwds))

    def match(self, *a, **kwds):
        return list(self.itermatch(*a, **kwds))

    __getattr__ = GetAttrProxy("raw_repo")
    __dir__ = DirProxy("raw_repo")

    def __iter__(self):
        return self.itermatch(packages.AlwaysTrue)
Example #3
0
class tree(prototype.tree):
    """Repository wrapper binding configuration data to contained packages."""

    operation_kls = repo.operations_proxy

    def __init__(self, repo, package_class):
        """
        :param repo: :obj:`pkgcore.repository.prototype.tree` instance to wrap
        :param package_class: callable to yield the package instance
        """
        self.raw_repo = repo
        if not isinstance(self.raw_repo, prototype.tree):
            raise errors.InitializationError(
                f'{self.raw_repo!r} is not a repository tree derivative')
        self.package_class = package_class
        self.raw_repo = repo

    def itermatch(self, *args, **kwargs):
        return map(self.package_class, self.raw_repo.itermatch(*args, **kwargs))

    __getattr__ = GetAttrProxy("raw_repo")
    __dir__ = DirProxy("raw_repo")

    def __len__(self):
        return len(self.raw_repo)
Example #4
0
class tree(prototype.tree):

    configured = True
    operations_kls = operations_proxy

    def __init__(self, raw_repo, wrapped_attrs, pkg_kls_injections=()):
        """
        :param raw_repo: repo to wrap
        :type raw_repo: :obj:`pkgcore.repository.prototype.tree`
        :param wrapped_attrs: sequence of attrs to wrap for each pkg
        """
        # yes, we're intentionally not using tree's init.
        # not perfect I know.
        self.raw_repo = raw_repo
        self.wrapped_attrs = wrapped_attrs
        self._pkg_klass = self._mk_kls(pkg_kls_injections)

    def _mk_kls(self, pkg_kls_injections):
        return make_wrapper(self,
                            self.configurable,
                            self.wrapped_attrs,
                            kls_injections=pkg_kls_injections)

    def _get_pkg_kwds(self, pkg):
        raise NotImplementedError

    def package_class(self, pkg):
        return self._pkg_klass(pkg, **self._get_pkg_kwds(pkg))

    @property
    def pkg_masks(self):
        # required to override empty pkg_masks inherited from prototype.tree
        return self.raw_repo.pkg_masks

    __getattr__ = GetAttrProxy("raw_repo")
    __dir__ = DirProxy("raw_repo")

    def itermatch(self, restrict, **kwds):
        kwds.setdefault("force", True)
        o = kwds.get("pkg_cls")
        if o is not None:
            kwds["pkg_cls"] = partial(self.package_class, o)
        else:
            kwds["pkg_cls"] = self.package_class
        return self.raw_repo.itermatch(restrict, **kwds)

    itermatch.__doc__ = prototype.tree.itermatch.__doc__.replace(
        "@param", "@keyword").replace(":keyword restrict:", ":param restrict:")

    def __getitem__(self, key):
        obj = self.package_class(self.raw_repo[key])
        if not obj.is_supported:
            raise KeyError(key)
        return obj

    def __repr__(self):
        return '<%s.%s raw_repo=%r wrapped=%r @%#8x>' % (
            self.__class__.__module__, self.__class__.__name__,
            getattr(self, 'raw_repo', 'unset'),
            list(getattr(self, 'wrapped_attrs', {}).keys()), id(self))
Example #5
0
class tree(prototype.tree):
    """wrap an existing repository yielding wrapped packages."""

    operation_kls = repo.operations_proxy

    def __init__(self, repo, package_class):
        """
        :param repo: :obj:`pkgcore.repository.prototype.tree` instance to wrap
        :param package_class: callable to yield the package instance
        """
        self.raw_repo = repo
        if not isinstance(self.raw_repo, prototype.tree):
            raise errors.InitializationError(
                "%s is not a repository tree derivative" % (self.raw_repo, ))
        self.package_class = package_class
        self.raw_repo = repo

    def itermatch(self, *args, **kwargs):
        pkgs = (x for x in self.raw_repo.itermatch(*args, **kwargs)
                if x.is_supported)
        return imap(self.package_class, pkgs)

    __getattr__ = GetAttrProxy("raw_repo")

    def __len__(self):
        return len(self.raw_repo)
Example #6
0
class ObserverFormatter(object):
    def __init__(self, real_formatter):
        self._formatter = real_formatter

    def write(self, *args):
        self._formatter.write(autoline=False, *args)

    __getattr__ = GetAttrProxy("_formatter")
Example #7
0
class tree(prototype.tree):
    """Filter existing repository based upon passed in restrictions."""

    operations_kls = operations_proxy

    def __init__(self, repo, restrict, sentinel_val=False):
        self.raw_repo = repo
        self.sentinel_val = sentinel_val
        if not hasattr(self.raw_repo, 'itermatch'):
            raise errors.InitializationError(
                f"{self.raw_repo} is not a repository tree derivative")
        if not isinstance(restrict, restriction.base):
            raise errors.InitializationError(f"{restrict} is not a restriction")
        self.restrict = restrict
        self.raw_repo = repo
        if sentinel_val:
            self._filterfunc = filter
        else:
            self._filterfunc = filterfalse

    def itermatch(self, restrict, **kwds):
        # note that this lets the repo do the initial filtering.
        # better design would to analyze the restrictions, and inspect
        # the repo, determine what can be done without cost
        # (determined by repo's attributes) versus what does cost
        # (metadata pull for example).
        return self._filterfunc(
            self.restrict.match, self.raw_repo.itermatch(restrict, **kwds))

    itermatch.__doc__ = prototype.tree.itermatch.__doc__.replace(
        "@param", "@keyword").replace(":keyword restrict:", ":param restrict:")

    def __len__(self):
        count = 0
        for i in self:
            count += 1
        return count

    __getattr__ = GetAttrProxy("raw_repo")
    __dir__ = DirProxy("raw_repo")

    def __getitem__(self, key):
        v = self.raw_repo[key]
        if self.restrict.match(v) != self.sentinel_val:
            raise KeyError(key)
        return v

    def __repr__(self):
        return '<%s raw_repo=%r restrict=%r sentinel=%r @%#8x>' % (
            self.__class__.__name__,
            getattr(self, 'raw_repo', 'unset'),
            getattr(self, 'restrict', 'unset'),
            getattr(self, 'sentinel_val', 'unset'),
            id(self))
Example #8
0
class caching_repo(object):

    """
    repository wrapper that overrides match, returning
    :obj:`caching_iter` instances; itermatch is slaved to match,
    in other words iterating over the caching_iter.

    Main use for this is to cache results from query lookups;
    if matches restrict arg is in the cache, the caller gets a shared
    caching_iter sequence, which may already be fully loaded with pkg
    instances.

    This can boost random lookup time pretty nicely, while helping to
    hold instance in memory to avoid redoing work.

    Cost of this of course is that involved objects are forced to stay
    in memory till the cache is cleared.  General use, not usually what
    you want- if you're making a lot of random queries that are duplicates
    (resolver does this for example), caching helps.
    """

    operations_kls = operations_proxy

    def __init__(self, db, strategy):
        """
        :param db: an instance supporting the repository protocol to cache
          queries from.
        :param strategy: forced sorting strategy for results.  If you don't
          need sorting, pass in iter.
        """
        self.__db__ = db
        self.__strategy__ = strategy
        self.__cache__ = {}

    def match(self, restrict):
        v = self.__cache__.get(restrict)
        if v is None:
            v = self.__cache__[restrict] = \
                caching_iter(
                    self.__db__.itermatch(restrict, sorter=self.__strategy__))
        return v

    def itermatch(self, restrict):
        return iter(self.match(restrict))

    __getattr__ = GetAttrProxy("__db__")

    def clear(self):
        self.__cache__.clear()
Example #9
0
class restrict_repo:
    """Repository wrapper that skips packages matching a given restriction."""
    def __init__(self, restrict, repo):
        """
        :param restrict: package matching restriction
        :param repo: repository to wrap
        """
        self.raw_repo = repo
        self.restrict = restrict

    def itermatch(self, *a, **kwds):
        return (x for x in self.raw_repo.itermatch(*a, **kwds)
                if not self.restrict.match(x))

    def match(self, *a, **kwds):
        return list(self.itermatch(*a, **kwds))

    __getattr__ = GetAttrProxy("raw_repo")
    __dir__ = DirProxy("raw_repo")

    def __iter__(self):
        return self.itermatch(packages.AlwaysTrue)