Example #1
0
    def matchPackageNames(self, pkgspecs):
        """take a list strings and match the packages in the sack against it
           this will match against:
           name
           name.arch
           name-ver-rel.arch
           name-ver
           name-ver-rel
           epoch:name-ver-rel.arch
           name-epoch:ver-rel.arch
           
           return [exact matches], [glob matches], [unmatch search terms]
           """
        # Setup match() for the search we're doing
        matched = []
        exactmatch = []
        unmatched = set(pkgspecs)

        specs = {}
        for p in pkgspecs:
            specs[p] = misc.compile_pattern(p)

        #  We don't use simplePkgList() here because that loads all of the
        # rpmdb, if we are Eg. doing a "remove PackageKit".
        pkgs = self.returnPackages(patterns=unmatched)
        for pkgtup in [pkg.pkgtup for pkg in pkgs]:
            (n, a, e, v, r) = pkgtup
            names = set(
                (
                    n,
                    "%s.%s" % (n, a),
                    "%s-%s-%s.%s" % (n, v, r, a),
                    "%s-%s" % (n, v),
                    "%s-%s-%s" % (n, v, r),
                    "%s:%s-%s-%s.%s" % (e, n, v, r, a),
                    "%s-%s:%s-%s.%s" % (n, e, v, r, a),
                )
            )

            for (term, query) in specs.items():
                if term in names:
                    exactmatch.append(self.searchPkgTuple(pkgtup)[0])
                    unmatched.discard(term)
                else:
                    for n in names:
                        if query(n):
                            matched.append(self.searchPkgTuple(pkgtup)[0])
                            unmatched.discard(term)
        return misc.unique(exactmatch), misc.unique(matched), list(unmatched)
    def matchPackageNames(self, pkgspecs):
        """take a list strings and match the packages in the sack against it
           this will match against:
           name
           name.arch
           name-ver-rel.arch
           name-ver
           name-ver-rel
           epoch:name-ver-rel.arch
           name-epoch:ver-rel.arch
           
           return [exact matches], [glob matches], [unmatch search terms]
           """
        # Setup match() for the search we're doing
        matched = []
        exactmatch = []
        unmatched = set(pkgspecs)

        specs = {}
        for p in pkgspecs:
            specs[p] = misc.compile_pattern(p)

        #  We don't use simplePkgList() here because that loads all of the
        # rpmdb, if we are Eg. doing a "remove PackageKit".
        pkgs = self.returnPackages(patterns=unmatched)
        for pkgtup in [pkg.pkgtup for pkg in pkgs]:
            (n, a, e, v, r) = pkgtup
            names = set((
                n,
                '%s.%s' % (n, a),
                '%s-%s-%s.%s' % (n, v, r, a),
                '%s-%s' % (n, v),
                '%s-%s-%s' % (n, v, r),
                '%s:%s-%s-%s.%s' % (e, n, v, r, a),
                '%s-%s:%s-%s.%s' % (n, e, v, r, a),
            ))

            for (term, query) in specs.items():
                if term in names:
                    exactmatch.append(self.searchPkgTuple(pkgtup)[0])
                    unmatched.discard(term)
                else:
                    for n in names:
                        if query(n):
                            matched.append(self.searchPkgTuple(pkgtup)[0])
                            unmatched.discard(term)
        return misc.unique(exactmatch), misc.unique(matched), list(unmatched)
Example #3
0
    def findRepos(self, pattern, name_match=False, ignore_case=False):
        """ Find all repositories matching fnmatch `pattern` on the repo.id,
            can also do case insensitive searches and/or search on the name."""

        if pattern in self.repos:  # Minor opt. as we do this a lot...
            return [self.repos[pattern]]

        result = []

        for item in pattern.split(','):
            item = item.strip()
            match = misc.compile_pattern(item.strip(), ignore_case)
            for name, repo in self.repos.items():
                assert name == repo.id
                if match(name) or match(repo.ui_id):
                    result.append(repo)
                elif name_match and match(repo.name):
                    result.append(repo)

        return result
Example #4
0
    def findRepos(self, pattern, name_match=False, ignore_case=False):
        """ Find all repositories matching fnmatch `pattern` on the repo.id,
            can also do case insensitive searches and/or search on the name."""

        if pattern in self.repos: # Minor opt. as we do this a lot...
            return [self.repos[pattern]]

        result = []
        
        for item in pattern.split(','):
            item = item.strip()
            match = misc.compile_pattern(item.strip(), ignore_case)
            for name,repo in self.repos.items():
                assert name == repo.id
                if match(name) or match(repo.ui_id):
                    result.append(repo)
                elif name_match and match(repo.name):
                    result.append(repo)

        return result