Exemplo n.º 1
0
def typeFilter(l, filterSet):
    if not filterSet:
        return l

    filters = []
    if 'group' in filterSet:
        filters.append(trove.troveIsGroup)
    if 'package' in filterSet:
        filters.append(trove.troveIsPackage)
    if 'component' in filterSet:
        filters.append(trove.troveIsComponent)
    if 'fileset' in filterSet:
        filters.append(trove.troveIsFileSet)
    if 'collection' in filterSet:
        filters.append(trove.troveIsCollection)
    if 'source' in filterSet:
        filters.append(trove.troveIsSourceComponent)
    if 'binarycomponent' in filterSet:
        filters.append(lambda x: trove.troveIsComponent(x) and
                                 not trove.troveIsSourceComponent(x))

    filters.append(None)

    filteredL = []
    for item in l:
        if filters:
            for f in filters:
                if f and f(item[0]): break
            if f is None:
                continue

        filteredL.append(item)

    return filteredL
Exemplo n.º 2
0
def typeFilter(l, filterSet):
    if not filterSet:
        return l

    filters = []
    if 'group' in filterSet:
        filters.append(trove.troveIsGroup)
    if 'package' in filterSet:
        filters.append(trove.troveIsPackage)
    if 'component' in filterSet:
        filters.append(trove.troveIsComponent)
    if 'fileset' in filterSet:
        filters.append(trove.troveIsFileSet)
    if 'collection' in filterSet:
        filters.append(trove.troveIsCollection)
    if 'source' in filterSet:
        filters.append(trove.troveIsSourceComponent)
    if 'binarycomponent' in filterSet:
        filters.append(lambda x: trove.troveIsComponent(x) and
                                 not trove.troveIsSourceComponent(x))

    filters.append(None)

    filteredL = []
    for item in l:
        if filters:
            for f in filters:
                if f and f(item[0]): break
            if f is None:
                continue

        filteredL.append(item)

    return filteredL
Exemplo n.º 3
0
def searchNodes(cu, roleIds, label = None, mkUrl = None, filterSet = None,
                db = None, name = None, latest = 1):
    args = []
    d = { 'labelCheck' : '', 'itemCheck' : '' }
    d['roleIds'] = ",".join( str(x) for x in roleIds)
    d['SOURCENAME'] = trove._TROVEINFO_TAG_SOURCENAME
    d['METADATA'] = trove._TROVEINFO_TAG_METADATA

    if label:
        d['labelCheck'] = "label = ? AND"
        args.append(label)

    if name:
        d['itemCheck'] = "item = ? AND"
        args.append(name)

    if latest:
        cu.execute("""
            SELECT idTable.item, version, ts, finalTs, SourceNameTroveInfo.data,
                   MetadataTroveInfo.data FROM
                (SELECT DISTINCT Items.item AS item,
                                 Nodes.versionId AS versionId,
                                 Nodes.timeStamps AS ts,
                                 Nodes.finalTimeStamp as finalTs,
                                 MIN(Instances.instanceId) AS instanceId
                    FROM Labels
                    JOIN LabelMap USING (labelId)
                    JOIN LatestCache USING (itemId, branchId)
                    JOIN Nodes USING (itemId, versionId)
                    JOIN Instances USING (itemId, versionId)
                    JOIN Items USING (itemId)
                    WHERE %(labelCheck)s
                          %(itemCheck)s
                          LatestCache.latestType = 1 AND
                          LatestCache.userGroupId in (%(roleIds)s)
                    GROUP BY
                          Items.item, Nodes.versionId, Nodes.timeStamps,
                          Nodes.finalTimestamp)
                AS idTable
                JOIN Versions ON (idTable.versionId = Versions.versionId)
                LEFT OUTER JOIN TroveInfo AS SourceNameTroveInfo ON
                    idTable.instanceId = SourceNameTroveInfo.instanceId AND
                    SourceNameTroveInfo.infoType = %(SOURCENAME)d
                LEFT OUTER JOIN TroveInfo AS MetadataTroveInfo ON
                    idTable.instanceId = MetadataTroveInfo.instanceId AND
                    MetadataTroveInfo.infoType = %(METADATA)d
        """ % d, args)
    else:
        cu.execute("""
            SELECT idTable.item, version, ts, finalTs, SourceNameTroveInfo.data,
                   MetadataTroveInfo.data FROM
                (SELECT DISTINCT Items.item AS item,
                                 Nodes.versionId AS versionId,
                                 Nodes.timeStamps AS ts,
                                 Nodes.finalTimeStamp as finalTs,
                                 MIN(Instances.instanceId) AS instanceId
                    FROM Labels
                    JOIN LabelMap USING (labelId)
                    JOIN Nodes USING (itemId, branchId)
                    JOIN Instances USING (itemId, versionId)
                    JOIN Items USING (itemId)
                    JOIN usergroupinstancescache AS ugi ON
                        Instances.instanceId = ugi.instanceId
                    WHERE %(labelCheck)s
                          %(itemCheck)s
                          ugi.userGroupId in (%(roleIds)s)
                    GROUP BY
                          Items.item, Nodes.versionId, Nodes.timeStamps,
                          Nodes.finalTimestamp)
                AS idTable
                JOIN Versions ON (idTable.versionId = Versions.versionId)
                LEFT OUTER JOIN TroveInfo AS SourceNameTroveInfo ON
                    idTable.instanceId = SourceNameTroveInfo.instanceId AND
                    SourceNameTroveInfo.infoType = %(SOURCENAME)d
                LEFT OUTER JOIN TroveInfo AS MetadataTroveInfo ON
                    idTable.instanceId = MetadataTroveInfo.instanceId AND
                    MetadataTroveInfo.infoType = %(METADATA)d
        """ % d, args)

    l = list(cu)
    filteredL = typeFilter(l, filterSet)

    # sort based on (name, version, desc(finalTimestamp))
    def sortorder(x, y):
        c = cmp(x[0], y[0])
        if c:
            return c

        return -(cmp(x[3], y[3]))

    filteredL.sort(sortorder)

    if latest:
        # keep the latest
        newL = []
        last = None
        for item in filteredL:
            if last and last[0] == item[0]:
                continue

            newL.append(item)
            last = item

        filteredL = newL

    nodeList = datamodel.NamedNodeList(total = len(filteredL), start = 0)

    addList = []
    for (name, version, ts, finalTs, sourceName, metadata) in filteredL:
        sourceName = cu.frombinary(sourceName)
        if sourceName is None and trove.troveIsSourceComponent(name):
            sourceName = name
        addList.append((sourceName,
                str(versions.VersionFromString(version).getSourceVersion())))

    schema.resetTable(cu, 'tmpNVF')

    # This is painful, but it converts the source name from a blob to
    # a string
    db.bulkload("tmpNVF", [ (x[0],) + x[1] for x in enumerate(addList) ],
                ["idx", "name", "version"],
                start_transaction = False)
    cu.execute("""
        SELECT ChangeLogs.name, ChangeLogs.message, tmpNVF.name
            FROM tmpNVF JOIN Items AS SourceItems ON
                tmpNVF.name = SourceItems.item
            LEFT OUTER JOIN Versions AS SourceVersion ON
                tmpNVF.version = SourceVersion.version
            LEFT OUTER JOIN Nodes ON
                SourceItems.itemId = Nodes.itemId AND
                SourceVersion.versionId = Nodes.versionId
            LEFT OUTER JOIN ChangeLogs USING (nodeId)
            ORDER BY tmpNVF.idx
    """)

    for ( (name, version, ts, finalTs, sourceName, metadata),
          (clName, clMessage, troveName) ) in itertools.izip(filteredL, cu):
        frzVer = versions.strToFrozen(version,
                                      [ x for x in ts.split(":") ])
        ver = versions.ThawVersion(frzVer)

        shortdesc = None

        if metadata:
            metadata = cu.frombinary(metadata)
            md = trove.Metadata(metadata)
            shortdesc = md.get()['shortDesc']

        if clName:
            cl = datamodel.ChangeLog(name = clName, message = clMessage)
        else:
            cl = None

        nodeList.append(name = name, version = ver, mkUrl = mkUrl,
                        changeLog = cl, shortdesc = shortdesc)

    return nodeList
Exemplo n.º 4
0
def searchNodes(cu, roleIds, label = None, mkUrl = None, filterSet = None,
                db = None, name = None, latest = 1):
    args = []
    d = { 'labelCheck' : '', 'itemCheck' : '' }
    d['roleIds'] = ",".join( str(x) for x in roleIds)
    d['SOURCENAME'] = trove._TROVEINFO_TAG_SOURCENAME
    d['METADATA'] = trove._TROVEINFO_TAG_METADATA

    if label:
        d['labelCheck'] = "label = ? AND"
        args.append(label)

    if name:
        d['itemCheck'] = "item = ? AND"
        args.append(name)

    if latest:
        cu.execute("""
            SELECT idTable.item, version, ts, finalTs, SourceNameTroveInfo.data,
                   MetadataTroveInfo.data FROM
                (SELECT DISTINCT Items.item AS item,
                                 Nodes.versionId AS versionId,
                                 Nodes.timeStamps AS ts,
                                 Nodes.finalTimeStamp as finalTs,
                                 MIN(Instances.instanceId) AS instanceId
                    FROM Labels
                    JOIN LabelMap USING (labelId)
                    JOIN LatestCache USING (itemId, branchId)
                    JOIN Nodes USING (itemId, versionId)
                    JOIN Instances USING (itemId, versionId)
                    JOIN Items USING (itemId)
                    WHERE %(labelCheck)s
                          %(itemCheck)s
                          LatestCache.latestType = 1 AND
                          LatestCache.userGroupId in (%(roleIds)s)
                    GROUP BY
                          Items.item, Nodes.versionId, Nodes.timeStamps,
                          Nodes.finalTimestamp)
                AS idTable
                JOIN Versions ON (idTable.versionId = Versions.versionId)
                LEFT OUTER JOIN TroveInfo AS SourceNameTroveInfo ON
                    idTable.instanceId = SourceNameTroveInfo.instanceId AND
                    SourceNameTroveInfo.infoType = %(SOURCENAME)d
                LEFT OUTER JOIN TroveInfo AS MetadataTroveInfo ON
                    idTable.instanceId = MetadataTroveInfo.instanceId AND
                    MetadataTroveInfo.infoType = %(METADATA)d
        """ % d, args)
    else:
        cu.execute("""
            SELECT idTable.item, version, ts, finalTs, SourceNameTroveInfo.data,
                   MetadataTroveInfo.data FROM
                (SELECT DISTINCT Items.item AS item,
                                 Nodes.versionId AS versionId,
                                 Nodes.timeStamps AS ts,
                                 Nodes.finalTimeStamp as finalTs,
                                 MIN(Instances.instanceId) AS instanceId
                    FROM Labels
                    JOIN LabelMap USING (labelId)
                    JOIN Nodes USING (itemId, branchId)
                    JOIN Instances USING (itemId, versionId)
                    JOIN Items USING (itemId)
                    JOIN usergroupinstancescache AS ugi ON
                        Instances.instanceId = ugi.instanceId
                    WHERE %(labelCheck)s
                          %(itemCheck)s
                          ugi.userGroupId in (%(roleIds)s)
                    GROUP BY
                          Items.item, Nodes.versionId, Nodes.timeStamps,
                          Nodes.finalTimestamp)
                AS idTable
                JOIN Versions ON (idTable.versionId = Versions.versionId)
                LEFT OUTER JOIN TroveInfo AS SourceNameTroveInfo ON
                    idTable.instanceId = SourceNameTroveInfo.instanceId AND
                    SourceNameTroveInfo.infoType = %(SOURCENAME)d
                LEFT OUTER JOIN TroveInfo AS MetadataTroveInfo ON
                    idTable.instanceId = MetadataTroveInfo.instanceId AND
                    MetadataTroveInfo.infoType = %(METADATA)d
        """ % d, args)

    l = list(cu)
    filteredL = typeFilter(l, filterSet)

    # sort based on (name, version, desc(finalTimestamp))
    def sortorder(x, y):
        c = cmp(x[0], y[0])
        if c:
            return c

        return -(cmp(x[3], y[3]))

    filteredL.sort(sortorder)

    if latest:
        # keep the latest
        newL = []
        last = None
        for item in filteredL:
            if last and last[0] == item[0]:
                continue

            newL.append(item)
            last = item

        filteredL = newL

    nodeList = datamodel.NamedNodeList(total = len(filteredL), start = 0)

    addList = []
    for (name, version, ts, finalTs, sourceName, metadata) in filteredL:
        sourceName = cu.frombinary(sourceName)
        if sourceName is None and trove.troveIsSourceComponent(name):
            sourceName = name
        addList.append((sourceName,
                str(versions.VersionFromString(version).getSourceVersion())))

    schema.resetTable(cu, 'tmpNVF')

    # This is painful, but it converts the source name from a blob to
    # a string
    db.bulkload("tmpNVF", [ (x[0],) + x[1] for x in enumerate(addList) ],
                ["idx", "name", "version"],
                start_transaction = False)
    cu.execute("""
        SELECT ChangeLogs.name, ChangeLogs.message, tmpNVF.name
            FROM tmpNVF JOIN Items AS SourceItems ON
                tmpNVF.name = SourceItems.item
            LEFT OUTER JOIN Versions AS SourceVersion ON
                tmpNVF.version = SourceVersion.version
            LEFT OUTER JOIN Nodes ON
                SourceItems.itemId = Nodes.itemId AND
                SourceVersion.versionId = Nodes.versionId
            LEFT OUTER JOIN ChangeLogs USING (nodeId)
            ORDER BY tmpNVF.idx
    """)

    for ( (name, version, ts, finalTs, sourceName, metadata),
          (clName, clMessage, troveName) ) in itertools.izip(filteredL, cu):
        frzVer = versions.strToFrozen(version,
                                      [ x for x in ts.split(":") ])
        ver = versions.ThawVersion(frzVer)

        shortdesc = None

        if metadata:
            metadata = cu.frombinary(metadata)
            md = trove.Metadata(metadata)
            shortdesc = md.get()['shortDesc']

        if clName:
            cl = datamodel.ChangeLog(name = clName, message = clMessage)
        else:
            cl = None

        nodeList.append(name = name, version = ver, mkUrl = mkUrl,
                        changeLog = cl, shortdesc = shortdesc)

    return nodeList