def iterTroves(self, troveInfoList, withFiles = True,
                   withFileStreams = False,
                   hidden = False, permCheckFilter = None):
        self.log(3, troveInfoList, "withFiles=%s withFileStreams=%s hidden=%s" % (
                        withFiles, withFileStreams, hidden))

        cu = self.db.cursor()
        schema.resetTable(cu, 'tmpNVF')
        schema.resetTable(cu, 'tmpInstanceId')

        l = []
        for idx, (n,v,f) in enumerate(troveInfoList):
            l.append((idx, n, v.asString(), f.freeze()))
        self.db.bulkload("tmpNVF", l, [ "idx", "name", "version", "flavor" ],
                         start_transaction = False)
        del l
        self.db.analyze("tmpNVF")

        args = [instances.INSTANCE_PRESENT_NORMAL]
        d = dict(presence = "Instances.isPresent = ?")
        if hidden:
            args.append(instances.INSTANCE_PRESENT_HIDDEN)
            d = dict(presence = "Instances.isPresent in (?,?)")
        d.update(self.db.keywords)
        cu.execute("""
        SELECT %(STRAIGHTJOIN)s tmpNVF.idx, Instances.instanceId, Instances.troveType,
               Nodes.timeStamps,
               Changelogs.name, ChangeLogs.contact, ChangeLogs.message
        FROM tmpNVF
        JOIN Items on tmpNVF.name = Items.item
        JOIN Versions on tmpNVF.version = Versions.version
        JOIN Flavors on tmpNVF.flavor = Flavors.flavor
        JOIN Instances on
            Items.itemId = Instances.itemId AND
            Versions.versionId = Instances.versionId AND
            Flavors.flavorId = Instances.flavorId
        JOIN Nodes on
            Instances.itemId = Nodes.itemId AND
            Instances.versionId = Nodes.versionId
        LEFT JOIN ChangeLogs using(nodeId)
        WHERE %(presence)s
        ORDER BY tmpNVF.idx
        """ % d, args)
        troveIdList = [ x for x in cu ]
        # short-circuit for cases when nothing matches
        if not troveIdList:
            for i in xrange(len(troveInfoList)):
                yield None
            return
        self.db.bulkload("tmpInstanceId",
                         [ x[0:2] for x in troveIdList ],
                         [ "idx", "instanceId" ],
                         start_transaction = False)
        self.db.analyze("tmpInstanceId")

        # filter out troves we don't have permissions for
        if permCheckFilter:
            permCheckFilter(cu, "tmpInstanceId")

            cu.execute("select idx from tmpInstanceId")
            validIndexes = set(x[0] for x in cu)
            troveIdList = [ x for x in troveIdList if x[0] in validIndexes ]

        # unfortunately most cost-based optimizers will get the
        # following troveTrovesCursor queries wrong. Details in CNY-2695

        # for PostgreSQL we have to force an execution plan that
        # uses the join order as coded in the query
        if self.db.kind == 'postgresql':
            cu.execute("set join_collapse_limit to 2")
            cu.execute("set enable_seqscan to off")

        troveTrovesCursor = self.db.cursor()
        # the STRAIGHTJOIN hack will ask MySQL to execute the query as written
        troveTrovesCursor.execute("""
        SELECT %(STRAIGHTJOIN)s tmpInstanceId.idx, Items.item, Versions.version,
            Flavors.flavor, TroveTroves.flags, Nodes.timeStamps
        FROM tmpInstanceId
        JOIN TroveTroves using(instanceId)
        JOIN Instances on TroveTroves.includedId = Instances.instanceId
        JOIN Items on Instances.itemId = Items.itemId
        JOIN Versions on Instances.versionId = Versions.versionId
        JOIN Flavors on Instances.flavorId = Flavors.flavorId
        JOIN Nodes on
            Instances.itemId = Nodes.itemId and
            Instances.versionId = Nodes.versionId
        ORDER BY tmpInstanceId.idx
        """ % self.db.keywords)
        troveTrovesCursor = util.PushIterator(troveTrovesCursor)

        # revert changes we forced on the postgresql optimizer
        if self.db.kind == 'postgresql':
            cu.execute("set join_collapse_limit to default")
            cu.execute("set enable_seqscan to default")

        troveFilesCursor = iter(())
        if withFileStreams or withFiles:
            troveFilesCursor = self.db.cursor()
            streamSel = "NULL"
            if withFileStreams:
                streamSel = "FileStreams.stream"
            troveFilesCursor.execute("""
            SELECT tmpInstanceId.idx, FilePaths.pathId,
                   Dirnames.dirname, Basenames.basename,
                   Versions.version, FileStreams.fileId, %s
            FROM tmpInstanceId
            JOIN TroveFiles using(instanceId)
            JOIN FileStreams using(streamId)
            JOIN FilePaths ON TroveFiles.filePathId = FilePaths.filePathId
            JOIN Dirnames ON FilePaths.dirnameId = Dirnames.dirnameId
            JOIN Basenames ON FilePaths.basenameId = Basenames.basenameId
            JOIN Versions ON TroveFiles.versionId = Versions.versionId
            ORDER BY tmpInstanceId.idx """ % (streamSel,))
        troveFilesCursor = util.PushIterator(troveFilesCursor)

        troveRedirectsCursor = self.db.cursor()
        troveRedirectsCursor.execute("""
        SELECT tmpInstanceId.idx, Items.item, Branches.branch, Flavors.flavor
        FROM tmpInstanceId
        JOIN TroveRedirects using (instanceId)
        JOIN Items using (itemId)
        JOIN Branches ON TroveRedirects.branchId = Branches.branchId
        LEFT JOIN Flavors ON TroveRedirects.flavorId = Flavors.flavorId
        ORDER BY tmpInstanceId.idx
        """)
        troveRedirectsCursor = util.PushIterator(troveRedirectsCursor)

        neededIdx = 0
        versionCache = VersionCache()
        flavorCache = FlavorCache()
        while troveIdList:
            (idx, troveInstanceId, troveType, timeStamps,
             clName, clVersion, clMessage) =  troveIdList.pop(0)

            # make sure we've returned something for everything up to this
            # point
            while neededIdx < idx:
                neededIdx += 1
                yield None

            # we need the one after this next time through
            neededIdx += 1

            singleTroveInfo = troveInfoList[idx]

            if clName is not None:
                changeLog = changelog.ChangeLog(clName, clVersion, clMessage)
            else:
                changeLog = None

            v = singleTroveInfo[1]
            key = (v, timeStamps)
            if versionCache.has_key(key):
                v = versionCache(key)
            else:
                v = v.copy()
                v.setTimeStamps([ float(x) for x in timeStamps.split(":") ])

            trv = trove.Trove(singleTroveInfo[0], v,
                              singleTroveInfo[2], changeLog,
                              type = troveType,
                              setVersion = False)

            try:
                next = troveTrovesCursor.next()
                while next[0] == idx:
                    idxA, name, version, flavor, flags, timeStamps = next
                    version = versionCache.get(version, timeStamps)
                    flavor = flavorCache.get(flavor)
                    byDefault = (flags & schema.TROVE_TROVES_BYDEFAULT) != 0
                    weakRef = (flags & schema.TROVE_TROVES_WEAKREF) != 0
                    trv.addTrove(name, version, flavor, byDefault = byDefault,
                                 weakRef = weakRef)
                    next = troveTrovesCursor.next()

                troveTrovesCursor.push(next)
            except StopIteration:
                # we're at the end; that's okay
                pass

            fileContents = {}
            try:
                next = troveFilesCursor.next()
                while next[0] == idx:
                    (idxA, pathId, dirname, basename, versionId, fileId,
                     stream) = next
                    fileId = cu.frombinary(fileId)
                    path = os.path.join(cu.frombinary(dirname),
                            cu.frombinary(basename))
                    version = versions.VersionFromString(versionId)
                    trv.addFile(cu.frombinary(pathId), path, version, fileId)
                    if stream is not None:
                        fileContents[fileId] = stream
                    next = troveFilesCursor.next()

                troveFilesCursor.push(next)
            except StopIteration:
                # we're at the end; that's okay
                pass

            try:
                next = troveRedirectsCursor.next()
                while next[0] == idx:
                    idxA, targetName, targetBranch, targetFlavor = next
                    targetBranch = versions.VersionFromString(targetBranch)
                    if targetFlavor is not None:
                        targetFlavor = deps.ThawFlavor(targetFlavor)

                    trv.addRedirect(targetName, targetBranch, targetFlavor)
                    next = troveRedirectsCursor.next()

                troveRedirectsCursor.push(next)
            except StopIteration:
                # we're at the end; that's okay
                pass

            self.depTables.get(cu, trv, troveInstanceId)
            self.troveInfoTable.getInfo(cu, trv, troveInstanceId)

            if withFileStreams:
                yield trv, fileContents
            else:
                yield trv

        # yield None for anything not found at the end
        while neededIdx < len(troveInfoList):
            neededIdx += 1
            yield None
dataset/ETHPy150Open sassoftware/conary/conary/repository/netrepos/trovestore.py/TroveStore.iterTroves/original