예제 #1
0
def importEntities(conn, cur, sg):
    debug.debug("starting import Entities", debug.INFO)

    entities = sg.schema_entity_read()

    classes = entities.keys()
    classes.sort()

    for entityType in classes:
        if entityType in ["EventLogEntry"]:
            continue

        if len(UPDATE_ONLY) > 0 and entityType not in UPDATE_ONLY:
            continue

        entityName = cleanSysName(entities[entityType]["name"]["value"])
        if entityType.endswith("Connection"):
            entityName = entityType

        debug.debug("import entities of type " + entityType)

        fieldList = connectors.getClassOfType(entityName).shotgun_fields

        debug.debug("deleting entities of type " + entityType)

        query = "DELETE FROM \"%s\"" % (entityType)
        cur.execute(query)

        debug.debug("loading entities of type " + entityType)
        objects = sg.find(entityType, [["id", "greater_than", 0]],
                          fieldList.keys())

        for obj in objects:
            values = []
            names = []
            reprs = []

            for fieldName in fieldList.keys():
                sgType = fieldList[fieldName]['data_type']['value']
                convFunc = connectors.getConversionSg2Pg(sgType)
                if convFunc != None:
                    names.append("\"%s\"" % fieldName)
                    if sgType == "image" and obj[fieldName] != None:
                        thumbnails.saveShotgunImageLocally(obj[fieldName])

                    if sgType == "multi_entity":
                        reprs.append("%s::entity_sync[]")
                    else:
                        reprs.append("%s")
                    values.append(convFunc(obj[fieldName]))

            query = "INSERT INTO \"%s\" (%s) VALUES (%s)" % (
                entityType, ", ".join(names), ", ".join(reprs))

            debug.debug(cur.mogrify(str(query), values), debug.DEBUG)
            cur.execute(query, values)

        conn.commit()
    debug.debug("finnished import Entities", debug.INFO)
예제 #2
0
def importEntities(conn, cur, sg):
    debug.debug("starting import Entities", debug.INFO)

    entities = sg.schema_entity_read()

    classes = entities.keys()
    classes.sort()

    for entityType in classes:
        if entityType in ["EventLogEntry"]:
            continue

        if len(UPDATE_ONLY) > 0 and entityType not in UPDATE_ONLY:
            continue

        entityName = cleanSysName(entities[entityType]["name"]["value"])
        if entityType.endswith("Connection"):
            entityName = entityType

        debug.debug("import entities of type " + entityType)

        fieldList = connectors.getClassOfType(entityName).shotgun_fields

        debug.debug("deleting entities of type " + entityType)

        query = 'DELETE FROM "%s"' % (entityType)
        cur.execute(query)

        debug.debug("loading entities of type " + entityType)
        objects = sg.find(entityType, [["id", "greater_than", 0]], fieldList.keys())

        for obj in objects:
            values = []
            names = []
            reprs = []

            for fieldName in fieldList.keys():
                sgType = fieldList[fieldName]["data_type"]["value"]
                convFunc = connectors.getConversionSg2Pg(sgType)
                if convFunc != None:
                    names.append('"%s"' % fieldName)
                    if sgType == "image" and obj[fieldName] != None:
                        thumbnails.saveShotgunImageLocally(obj[fieldName])

                    if sgType == "multi_entity":
                        reprs.append("%s::entity_sync[]")
                    else:
                        reprs.append("%s")
                    values.append(convFunc(obj[fieldName]))

            query = 'INSERT INTO "%s" (%s) VALUES (%s)' % (entityType, ", ".join(names), ", ".join(reprs))

            debug.debug(cur.mogrify(str(query), values), debug.DEBUG)
            cur.execute(query, values)

        conn.commit()
    debug.debug("finnished import Entities", debug.INFO)
 def test_retrieval_simple( self ):
     localpath = thumbnails.saveShotgunImageLocally( self.testnode.image )
     results = os.stat( localpath )
     debug.debug(results.st_mtime)
     self.assertTrue(results.st_mtime > time.time() - 20, "file does not seem to have been written lately")