def resolve(self, groupIds, label, depList, troveList=[], leavesOnly = False):
        cu = self.db.cursor()
        # need to make sure that depList does not contain duplicates
        # for efficiency reasons
        requires = {}
        for depStr in depList:
            depSet = deps.ThawDependencySet(depStr)
            requires[depSet] = depStr
        depSetList = requires.keys()
        depNums = self._setupDepSets(cu, depSetList)

        # 1. look up inmstances whose provides fully satisfy all the
        #    flags of every depName within a depSet (flagCount check)
        # 2. out of those instances, only consider the ones that fully
        #    satisfy all the depName deps within a depSet (depCount
        #    check)
        # 3. filter only the instanceIds the user has access to
        query = """
        select distinct
            tmpDepNum.idx as idx, tmpDepNum.depNum as depNum,
            Items.item, flavor, version, Nodes.timeStamps,
            Nodes.finalTimestamp as finalTimestamp
        from tmpDepNum
        join (
            select
                tmpDeps.idx as idx,
                tmpDeps.depNum as depNum,
                Provides.instanceId as instanceid,
                count(*) as flagCount
            from tmpDeps
            join Dependencies using(class, name, flag)
            join Provides using(depId)
            group by tmpDeps.idx, tmpDeps.depNum, Provides.instanceId
        ) as DepSelect using(idx, depNum, flagCount)
        join Instances on
            Instances.instanceId = DepSelect.instanceId
        join Nodes using(itemId, versionId) """

        where = ["ugi.userGroupId in (%s)" % (
            ",".join("%d" % x for x in groupIds),)]
        args = []
        if troveList:
            self._setupTroveList(cu, troveList)
            query += """
            join tmpInstances as ti on ti.instanceId = Instances.instanceId
            join UserGroupInstancesCache as ugi on
                ugi.instanceId = ti.instanceId """
        else:
            if leavesOnly:
                query += """
                join LatestCache as ugi using (itemId, versionId, branchId) """
                where.append("ugi.latestType = %d" % trovesource.TROVE_QUERY_NORMAL)
                where.append("ugi.flavorId = Instances.flavorId")
            else:
                query += """
                join UserGroupInstancesCache as ugi on
                    ugi.instanceId = Instances.instanceId """
            # restrict by label
            if label:
                query += """
                join LabelMap on
                    Instances.itemId = LabelMap.itemId and
                    Nodes.branchId = LabelMap.branchId
                join Labels using (labelId) """
                where.append("Labels.label = ?")
                args.append(label)
        # final joins to allow us to extract the query results as strings
        query += """
        join Items on Instances.itemId = Items.itemId
        join Versions on Instances.versionId = Versions.versionId
        join Flavors on Instances.flavorId = Flavors.flavorId
        where %s
        order by idx, depNum, finalTimestamp desc """ % (
            " and ".join(where))
        cu.execute(query, args)

        # sqlite version 3.2.2 have trouble sorting correctly the
        # results from the previous query. If we're running on sqlite,
        # we take the hit here and resort the results in Python...
        if self.db.driver == "sqlite":
            # order by idx, depNum, finalTimestamp desc
            retList = sorted(cu, key = lambda a: (a[0], a[1], -a[6]))
        else:
            retList = cu

        ret = {}
        for (depId, depNum, troveName, flavorStr, versionStr, timeStamps, ft) in retList:
            retd = ret.setdefault(depId, [{} for x in xrange(depNums[depId])])
            # remember the first version of each (n,f) tuple for each query
            retd[depNum].setdefault((troveName, flavorStr), (versionStr, timeStamps))
        ret2 = {}
        for depId, depDictList in ret.iteritems():
            key = requires[depSetList[depId]]
            retList = ret2.setdefault(key, [ [] for x in xrange(len(depDictList)) ])
            for i, depDict in enumerate(depDictList):
                retList[i] = [ (trv[0], versions.strToFrozen(ver[0], ver[1].split(":")),
                                trv[1]) for trv, ver in depDict.iteritems() ]
        # fill in the result dictionary for the values we have not resolved deps for
        result = {}
        for depId, depSet in enumerate(depSetList):
            result.setdefault(requires[depSet],
                              [ [] for x in xrange(depNums[depId])])
        result.update(ret2)
        return result
Determine troves that provide the given dependencies,
dataset/ETHPy150Open sassoftware/conary/conary/repository/netrepos/deptable.py/DependencyTables.resolve