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 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 main(): """ to be called """ sg_url = "https://devilfant.shotgunstudio.com" sg_test1 = {"name": "test1", "key": "e398654c5ec1c6f7c8f71ead33349c58bbf4a058"} sg1 = Shotgun( sg_url, sg_test1["name"], sg_test1["key"] ) entities = sg1.schema_entity_read() pprint( entities ) moduleString = """# -*- coding: utf-8 -*- \"""@package shotgun_replica.entities Shotgun Entities THIS FILE IS AUTO GENERATED DO NOT EDIT IT DIRECTLY change create_shotgun_classes.py instead \""" from shotgun_replica._entity_mgmt import _ShotgunEntity from shotgun_replica import %s """ % FIELDDEFINITIONSMODULE fieldDefModuleString = """# -*- coding: utf-8 -*- \""" THIS FILE IS AUTO GENERATED DO NOT EDIT IT DIRECTLY change create_shotgun_classes.py instead \""" """ classes = entities.keys() classes.sort() for entitycode in classes: print "processing %s\n" % entitycode fieldDefs = sg1.schema_field_read( entitycode ) try: theclass = connectors.getClassOfType( entitycode ) localFieldDefs = theclass.shotgun_fields except ImportError: localFieldDefs = None except AttributeError: localFieldDefs = None if fieldDefs != localFieldDefs: debug.error( "%s fielddefs differ from shotgun to local" % entitycode ) entityname = cleanSysName( entities[entitycode]["name"]["value"] ) if entitycode.endswith( "Connection" ): entityname = entitycode ( classCode, fieldDefCode ) = _createClassCode( entities, entitycode, fieldDefs, entityname ) moduleString += classCode fieldDefModuleString += fieldDefCode _createDBFields( entitycode, fieldDefs, entityname ) packageDir = os.path.dirname( __file__ ) entityFilename = os.path.join( packageDir, 'entities.py' ) entity_file = open( entityFilename, 'w' ) entity_file.write( moduleString ) entity_file.close() fieldDefFilename = os.path.join( packageDir, '%s.py' % FIELDDEFINITIONSMODULE ) fieldDef_file = open( fieldDefFilename, 'w' ) fieldDef_file.write( fieldDefModuleString ) fieldDef_file.close()
def main(): """ to be called """ sg_url = "https://devilfant.shotgunstudio.com" sg_test1 = { "name": "test1", "key": "e398654c5ec1c6f7c8f71ead33349c58bbf4a058" } sg1 = Shotgun(sg_url, sg_test1["name"], sg_test1["key"]) entities = sg1.schema_entity_read() pprint(entities) moduleString = """# -*- coding: utf-8 -*- \"""@package shotgun_replica.entities Shotgun Entities THIS FILE IS AUTO GENERATED DO NOT EDIT IT DIRECTLY change create_shotgun_classes.py instead \""" from shotgun_replica._entity_mgmt import _ShotgunEntity from shotgun_replica import %s """ % FIELDDEFINITIONSMODULE fieldDefModuleString = """# -*- coding: utf-8 -*- \""" THIS FILE IS AUTO GENERATED DO NOT EDIT IT DIRECTLY change create_shotgun_classes.py instead \""" """ classes = entities.keys() classes.sort() for entitycode in classes: print "processing %s\n" % entitycode fieldDefs = sg1.schema_field_read(entitycode) try: theclass = connectors.getClassOfType(entitycode) localFieldDefs = theclass.shotgun_fields except ImportError: localFieldDefs = None except AttributeError: localFieldDefs = None if fieldDefs != localFieldDefs: debug.error("%s fielddefs differ from shotgun to local" % entitycode) entityname = cleanSysName(entities[entitycode]["name"]["value"]) if entitycode.endswith("Connection"): entityname = entitycode (classCode, fieldDefCode) = _createClassCode(entities, entitycode, fieldDefs, entityname) moduleString += classCode fieldDefModuleString += fieldDefCode _createDBFields(entitycode, fieldDefs, entityname) packageDir = os.path.dirname(__file__) entityFilename = os.path.join(packageDir, 'entities.py') entity_file = open(entityFilename, 'w') entity_file.write(moduleString) entity_file.close() fieldDefFilename = os.path.join(packageDir, '%s.py' % FIELDDEFINITIONSMODULE) fieldDef_file = open(fieldDefFilename, 'w') fieldDef_file.write(fieldDefModuleString) fieldDef_file.close()