def findTroves(self):
        sourceTroveMatches = self._findSourceTroves()
        trvCsDict = self._getSourceTroves(sourceTroveMatches)

        redirRuleMap = {}

        # sourceTroveVersions is all of the versions/flavors which
        # currently exist for this trove
        for sourceName, sourceTroveVersions in sourceTroveMatches.iteritems():
            # set of rules for where this trove should redirect to
            targetRules = self._getTargetRules(self.rules, sourceName)

            # XXX the repository operations should be pulled out of all of
            # these loops
            additionalNames = set()
            for rule in targetRules:
                # get all of the flavors this rule specifies redirecting to
                targetFlavors = rule.findAvailableTargetFlavors(self.repos)

                if rule.branchStr and not targetFlavors:
                    # We're redirecting to something which doesn't
                    # exist.
                    raise builderrors.RecipeFileError, \
                        "Trove %s does not exist" % (rule.destName)

                # This lets us catch where we haven't found any matches for
                # this rule. If we have found any matches for this rule, no
                # error results, even if some of the troves on that label
                # cannot be redirected due to flavor conflicts
                foundMatch = False

                # Try to create redirects for each version/flavor combination
                for sourceVersion, flavorList in sourceTroveVersions.items():
                    for sourceFlavor in flavorList:
                        if rule.sourceFlavor is not None and \
                           sourceFlavor != rule.sourceFlavor:
                            continue

                        match = None
                        for targetVersion, targetFlavor in targetFlavors:
                            if (not rule.skipTargetMatching and
                                rule.targetFlavor is not None and
                                targetFlavor != rule.targetFlavor):
                                continue

                            if ((rule.sourceFlavor is not None)
                                or rule.skipTargetMatching
                                or sourceFlavor.score(targetFlavor) is not False):
                                match = (targetVersion, targetFlavor)
                                break

                        if match is not None:
                            # found a compatible trove to redirect to
                            if (sourceName, sourceFlavor) in self.redirections:
                                # a default-flavor rule doesn't cause a
                                # conflict with a flavor-specifying rule
                                # because the later is more specific (and
                                # we know we've already processed the
                                # flavor-specifying rule because self.rules
                                # is sorted with flavor-specifying rules
                                # at the front)
                                previousRule = redirRuleMap[(sourceName,
                                                             sourceFlavor)]
                                if (previousRule.sourceFlavor
                                                    is not None and
                                    rule.sourceFlavor is None):
                                    # the default rule should be skipped
                                    # rather than causing a conflict
                                    continue

                                if not rule.allowMultipleTargets:
                                    raise builderrors.RecipeFileError, \
                                        "Multiple redirect targets specified " \
                                        "from trove %s[%s]" \
                                        % (sourceName, sourceFlavor)

                            targetTroveInfo = (rule.destName, match[0],
                                               match[1])
                        elif not targetFlavors:
                            # redirect to nothing
                            targetTroveInfo = (None, None, None)
                        elif rule.targetFlavor is not None:
                            raise builderrors.RecipeFileError, \
                                "Trove %s does not exist for flavor [%s]" \
                                % (sourceName, targetFlavor)
                        else:
                            continue

                        # we created a redirect!
                        foundMatch = True
                        redirRuleMap[(sourceName, sourceFlavor)] = rule

                        self._buildRedirect(trvCsDict, sourceFlavor,
                                            sourceVersion, rule,
                                            targetTroveInfo)


                if not foundMatch:
                    raise builderrors.CookError(
                    "Could not find target with satisfying flavor"
                    " for redirect %s - either create a redirect"
                    " with targetFlavor and sourceFlavor set, or"
                    " create a redirect with skipTargetMatching = True" % sourceName)
dataset/ETHPy150Open sassoftware/conary/conary/build/redirectrecipe.py/_RedirectRecipe.findTroves/original