Exemplo n.º 1
0
    def _do_complex_lookup(self, show_progress=True):
        """Find matches for a query which is a regex or includes globbing."""

        result = []

        if show_progress and not CONFIG["piping"]:
            self.print_summary()

        try:
            cat = CPV(self.query).category
        except errors.GentoolkitInvalidCPV:
            cat = ''

        pre_filter = []
        # The "get_" functions can pre-filter against the whole package key,
        # but since we allow globbing now, we run into issues like:
        # >>> portage.dep.dep_getkey("sys-apps/portage-*")
        # 'sys-apps/portage-'
        # So the only way to guarantee we don't overrun the key is to
        # prefilter by cat only.
        if cat:
            if self.is_regex:
                cat_re = cat
            else:
                cat_re = fnmatch.translate(cat)
            predicate = lambda x: re.match(cat_re, x.split("/", 1)[0])
            pre_filter = self.package_finder(predicate=predicate)

        # Post-filter
        if self.is_regex:
            try:
                re.compile(self.query)
            except re.error:
                raise errors.GentoolkitInvalidRegex(self.query)
            predicate = lambda x: re.search(self.query, x)
        else:
            if cat:
                query_re = fnmatch.translate(self.query)
            else:
                query_re = fnmatch.translate("*/%s" % self.query)
            predicate = lambda x: re.search(query_re, x)
        if pre_filter:
            result = [x for x in pre_filter if predicate(x)]
        else:
            result = self.package_finder(predicate=predicate)

        return [Package(x) for x in result]
Exemplo n.º 2
0
    def __call__(self, queries):
        """Run the function.

		@type queries: iterable
		@param queries: filepaths or filepath regexes
		"""
        query_re_string = self._prepare_search_regex(queries)
        try:
            query_re = re.compile(query_re_string)
        except (TypeError, re.error) as err:
            raise errors.GentoolkitInvalidRegex(err)

        use_match = False
        if ((self.is_regex or query_re_string.startswith('^\/'))
                and '|' not in query_re_string):
            # If we were passed a regex or a single path starting with root,
            # we can use re.match, else use re.search.
            use_match = True

        pkgset = get_installed_cpvs()

        return self.find_owners(query_re, use_match=use_match, pkgset=pkgset)