def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) fileLocationDir = os.path.dirname(fileLocation) absRefLoc = os.path.normcase( posixpath.normpath( os.path.join(self.productionDetails[2], self.currentFileLocation))) handle = blendfile.openBlendFile(fileLocation, 'r+b') libRef = 0 for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0] absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath == absRefLoc: libRef = libraryblock.OldAddress for idblock in handle.FindBlendFileBlocksWithCode("ID"): lib = idblock.Get("lib") if lib == libRef: name = idblock.Get("name").split("\0")[0] if name == self.elementDetails[2]: idblock.Set("name", self.newElementName) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) fileLocationDir = os.path.dirname(fileLocation) absNewLoc = os.path.normcase( posixpath.normpath( os.path.join( self.productionDetails[2], self.newFileDetails[indexer.INDEX_FILE_LOCATION]))) newpath = "//" + _relpath(absNewLoc, fileLocationDir) handle = blendfile.openBlendFile(fileLocation, 'r+b') if self.libraryDetails[indexer.INDEX_ELEMENT_TYPE] == 'LI': for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): path = libraryblock.Get("filename") if path == None: path = libraryblock.Get( "filepath") #blender 2.5 renamed field path = path.split("\0")[0].replace("\\", "/") if path == self.libraryDetails[ indexer.INDEX_ELEMENT_LI_FILENAME]: libraryblock.Set("name", newpath) elif self.libraryDetails[indexer.INDEX_ELEMENT_TYPE] == 'IM': for libraryblock in handle.FindBlendFileBlocksWithCode("IM"): path = libraryblock.Get("name").split("\0")[0] if path == self.libraryDetails[ indexer.INDEX_ELEMENT_LI_FILENAME]: libraryblock.Set("name", newpath) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) fileLocationDir = os.path.dirname(fileLocation) absRefLoc = os.path.normcase( posixpath.normpath( os.path.join(self.productionDetails[2], self.currentFileLocation))) absNewLoc = absRefLoc[0:len(absRefLoc) - len(self.currentFilename)] + self.newFilename newpath = "//" + _relpath(absNewLoc, fileLocationDir) handle = blendfile.openBlendFile(fileLocation, 'r+b') for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0].replace( "\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath == absRefLoc: libraryblock.Set("name", newpath) for imageblock in handle.FindBlendFileBlocksWithCode("IM"): relPath = imageblock.Get("name").split("\0")[0].replace("\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath == absRefLoc: imageblock.Set("name", newpath) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) fileLocationDir = os.path.dirname(fileLocation) absRefLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], self.currentFileLocation))) absNewLoc = absRefLoc[0:len(absRefLoc)-len(self.currentFilename)]+self.newFilename newpath = "//"+_relpath(absNewLoc, fileLocationDir) handle = blendfile.openBlendFile(fileLocation, 'r+b') for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0].replace("\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath==absRefLoc: libraryblock.Set("name", newpath) for imageblock in handle.FindBlendFileBlocksWithCode("IM"): relPath = imageblock.Get("name").split("\0")[0].replace("\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath==absRefLoc: imageblock.Set("name", newpath) handle.close()
def execute(self): productionLocation = self.productionDetails[indexer.INDEX_PRODUCTION_LOCATION] fileLocation = self.fileDetails[indexer.INDEX_FILE_LOCATION] fileLocation = os.path.join(productionLocation, fileLocation) subDirs = fileLocation.replace(self.sourceDirectory, self.targetDirectory, 1) fileLocationDir = os.path.dirname(subDirs) absRefLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], subDirs))) absNewLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], self.referenceFileDetails[indexer.INDEX_FILE_LOCATION]))) newpath = "//"+_relpath(absNewLoc, fileLocationDir) handle = blendfile.openBlendFile(fileLocation, 'r+b') for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0].replace("\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath==absNewLoc: libraryblock.Set("name", newpath) for imageblock in handle.FindBlendFileBlocksWithCode("IM"): relPath = imageblock.Get("name").split("\0")[0].replace("\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath==absNewLoc: imageblock.Set("name", newpath) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) handle = blendfile.openBlendFile(fileLocation, 'r+b') stype = self.elementDetails[1] for libraryblock in handle.FindBlendFileBlocksWithCode(stype): name = libraryblock.Get("id.name").split("\0")[0] if name == self.elementDetails[2]: libraryblock.Set("id.name", self.newElementName) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] currentFileLocation = os.path.normcase( os.path.normpath(os.path.join(productionLocation, fileLocation))) newFileLocation = os.path.normcase( os.path.normpath( os.path.join( productionLocation, os.path.join(self.newLocation, self.currentFilename)))) dirLocation = os.path.normcase( os.path.normpath(os.path.dirname(newFileLocation))) #create target directory if not existing if not os.path.exists(dirLocation): os.makedirs(dirLocation) if svn.isKnownSVNFile(currentFileLocation): svn.svnMove(currentFileLocation, newFileLocation) else: shutil.move(currentFileLocation, newFileLocation) #update ID and IM tags of blend files. if self.currentFilename.endswith(".blend"): handle = blendfile.openBlendFile(newFileLocation, 'r+b') for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0] absPath = blendfile.blendPath2AbsolutePath( currentFileLocation, relPath) normPath = os.path.normcase(os.path.normpath(absPath)) newRelPath = _relpath(normPath, dirLocation) libraryblock.Set("name", "//" + newRelPath) for libraryblock in handle.FindBlendFileBlocksWithCode("IM"): relPath = libraryblock.Get("name").split("\0")[0] if len(relPath) > 0: absPath = blendfile.blendPath2AbsolutePath( currentFileLocation, relPath) normPath = os.path.normcase(os.path.normpath(absPath)) newRelPath = _relpath(normPath, dirLocation) libraryblock.Set("name", "//" + newRelPath) handle.close() pass
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] currentFileLocation = os.path.normcase(os.path.normpath(os.path.join(productionLocation, fileLocation))) newFileLocation = os.path.normcase(os.path.normpath(os.path.join(productionLocation, os.path.join(self.newLocation, self.currentFilename)))) dirLocation = os.path.normcase(os.path.normpath(os.path.dirname(newFileLocation))) #create target directory if not existing if not os.path.exists(dirLocation): os.makedirs(dirLocation) if svn.isKnownSVNFile(currentFileLocation): svn.svnMove(currentFileLocation, newFileLocation) else: shutil.move(currentFileLocation, newFileLocation) #update ID and IM tags of blend files. if self.currentFilename.endswith(".blend"): handle = blendfile.openBlendFile(newFileLocation, 'r+b') for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0] absPath = blendfile.blendPath2AbsolutePath(currentFileLocation, relPath) normPath = os.path.normcase(os.path.normpath(absPath)) newRelPath = _relpath(normPath, dirLocation) libraryblock.Set("name", "//"+newRelPath) for libraryblock in handle.FindBlendFileBlocksWithCode("IM"): relPath = libraryblock.Get("name").split("\0")[0] if len(relPath)>0: absPath = blendfile.blendPath2AbsolutePath(currentFileLocation, relPath) normPath = os.path.normcase(os.path.normpath(absPath)) newRelPath = _relpath(normPath, dirLocation) libraryblock.Set("name", "//"+newRelPath) handle.close() pass
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) absRefLoc = self.libraryDetails[indexer.INDEX_ELEMENT_LI_FILENAME] handle = blendfile.openBlendFile(fileLocation, 'r+b') libRef = 0 for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("filename") if relPath == None: relPath = libraryblock.Get("filepath") relPath = relPath.split("\0")[0] if relPath == absRefLoc: libRef = libraryblock.OldAddress for idblock in handle.FindBlendFileBlocksWithCode("ID"): lib = idblock.Get("lib") if lib == libRef: name = idblock.Get("name").split("\0")[0] if name == self.elementDetails[indexer.INDEX_ELEMENT_NAME]: idblock.Set("name", self.newElementName) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) fileLocationDir = os.path.dirname(fileLocation) absNewLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], self.newFileDetails[indexer.INDEX_FILE_LOCATION]))) newpath = "//"+_relpath(absNewLoc, fileLocationDir) handle = blendfile.openBlendFile(fileLocation, 'r+b') if self.libraryDetails[indexer.INDEX_ELEMENT_TYPE] == 'LI': for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): path = libraryblock.Get("filename") if path == None: path = libraryblock.Get("filepath") #blender 2.5 renamed field path = path.split("\0")[0].replace("\\", "/") if path == self.libraryDetails[indexer.INDEX_ELEMENT_LI_FILENAME]: libraryblock.Set("name", newpath) elif self.libraryDetails[indexer.INDEX_ELEMENT_TYPE] == 'IM': for libraryblock in handle.FindBlendFileBlocksWithCode("IM"): path = libraryblock.Get("name").split("\0")[0] if path == self.libraryDetails[indexer.INDEX_ELEMENT_LI_FILENAME]: libraryblock.Set("name", newpath) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) absRefLoc = self.libraryDetails[indexer.INDEX_ELEMENT_LI_FILENAME] handle = blendfile.openBlendFile(fileLocation, 'r+b') libRef = 0 for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("filename") if relPath == None: relPath = libraryblock.Get("filepath") relPath = relPath.split("\0")[0] if relPath==absRefLoc: libRef = libraryblock.OldAddress for idblock in handle.FindBlendFileBlocksWithCode("ID"): lib = idblock.Get("lib") if lib == libRef: name = idblock.Get("name").split("\0")[0] if name == self.elementDetails[indexer.INDEX_ELEMENT_NAME]: idblock.Set("name", self.newElementName) handle.close()
def execute(self): productionLocation = self.productionDetails[2] fileLocation = self.fileDetails[3] fileLocation = os.path.join(productionLocation, fileLocation) fileLocationDir = os.path.dirname(fileLocation) absRefLoc = os.path.normcase(posixpath.normpath(os.path.join(self.productionDetails[2], self.currentFileLocation))) handle = blendfile.openBlendFile(fileLocation, 'r+b') libRef = 0 for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0] absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath==absRefLoc: libRef = libraryblock.OldAddress for idblock in handle.FindBlendFileBlocksWithCode("ID"): lib = idblock.Get("lib") if lib == libRef: name = idblock.Get("name").split("\0")[0] if name == self.elementDetails[2]: idblock.Set("name", self.newElementName) handle.close()
def execute(self): productionLocation = self.productionDetails[ indexer.INDEX_PRODUCTION_LOCATION] fileLocation = self.fileDetails[indexer.INDEX_FILE_LOCATION] fileLocation = os.path.join(productionLocation, fileLocation) subDirs = fileLocation.replace(self.sourceDirectory, self.targetDirectory, 1) fileLocationDir = os.path.dirname(subDirs) absRefLoc = os.path.normcase( posixpath.normpath(os.path.join(self.productionDetails[2], subDirs))) absNewLoc = os.path.normcase( posixpath.normpath( os.path.join( self.productionDetails[2], self.referenceFileDetails[indexer.INDEX_FILE_LOCATION]))) newpath = "//" + _relpath(absNewLoc, fileLocationDir) handle = blendfile.openBlendFile(fileLocation, 'r+b') for libraryblock in handle.FindBlendFileBlocksWithCode("LI"): relPath = libraryblock.Get("name").split("\0")[0].replace( "\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath == absNewLoc: libraryblock.Set("name", newpath) for imageblock in handle.FindBlendFileBlocksWithCode("IM"): relPath = imageblock.Get("name").split("\0")[0].replace("\\", "/") absPath = blendfile.blendPath2AbsolutePath(fileLocation, relPath) normPath = os.path.normpath(absPath) if normPath == absNewLoc: imageblock.Set("name", newpath) handle.close()
def indexNewFile(connection, productionId, productionDir, file, useFileId=None): """index a new file""" if useFileId == None: newId = connection.execute("select max(id)+1 from file").fetchone()[0] if newId == None: newId = 0 connection.execute( "insert into file values (?,?,?,?,?,?)", [ newId, productionId, os.path.basename(file), _relpath(file, productionDir), int(os.path.getmtime(file)), int(os.path.getsize(file)), ], ) else: newId = useFileId connection.execute( "update file set lastupdate=?, length=? where id=?", [int(os.path.getmtime(file)), int(os.path.getsize(file)), newId], ) if file.endswith(".blend"): log.info("indexing file " + file) bf = blendfile.openBlendFile(file) # index the file firstElementId = connection.execute("select max(id)+1 from element").fetchone()[0] offsetElementId = 0 if firstElementId == None: firstElementId = 0 bfVersion = bf.Header.Version bfPointerSize = bf.Header.PointerSize bfLittleEndianness = bf.Header.LittleEndianness bfCompressed = bf.compressed bfCurrentScenePointer = None bfElementId = firstElementId offsetElementId = offsetElementId + 1 bfCurrentSceneId = None for block in bf.FindBlendFileBlocksWithCode("GLOB"): bfCurrentScenePointer = block.Get("curscene") # flags=block.Get("fileflags") # bfCompressed = (flags & G_FILE_COMPRESS) == G_FILE_COMPRESS # print(flags, bfCompressed) for block in bf.FindBlendFileBlocksWithCode("SC"): scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 if block.OldAddress == bfCurrentScenePointer: bfCurrentSceneId = scId scName = block.Get("id.name") scWidth = block.Get("r.xsch") scHeight = block.Get("r.ysch") scSize = block.Get("r.size") scXparts = block.Get("r.xparts") scYparts = block.Get("r.yparts") scStartFrame = block.Get("r.sfra") scEndFrame = block.Get("r.efra") scStep = block.Get("frame_step") scImageType = formatImageType(block.Get("r.imtype")) connection.execute( "insert into element (id, file_id, blendfile_id, name, type, sc_width, sc_height, sc_size, sc_xparts, sc_yparts, sc_startframe, sc_endframe, sc_framestep, sc_outputtype) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", [ scId, newId, bfElementId, scName, scName[0:2], scWidth, scHeight, scSize, scXparts, scYparts, scStartFrame, scEndFrame, scStep, scImageType, ], ) for block in bf.FindBlendFileBlocksWithCode("MA"): scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 scName = block.Get("id.name") connection.execute( "insert into element (id, file_id, blendfile_id, name, type) values (?,?,?,?,?)", [scId, newId, bfElementId, scName, scName[0:2]], ) for block in bf.FindBlendFileBlocksWithCode("OB"): # sdna = block.SDNAIndex dnaIndex = block.SDNAIndex dnaStruct = block.File.Catalog.Structs[dnaIndex] if dnaStruct.Type[0] == "Object": scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 scName = block.Get("id.name") connection.execute( "insert into element (id, file_id, blendfile_id, name, type) values (?,?,?,?,?)", [scId, newId, bfElementId, scName, scName[0:2]], ) for type in [ "AC", "AR", "BR", "CA", "CU", "GD", "GR", "IP", "LA", "LT", "MB", "ME", "NT", "SO", "TE", "TX", "VF", "WO", "KE", ]: for block in bf.FindBlendFileBlocksWithCode(type): scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 scName = block.Get("id.name") connection.execute( "insert into element (id, file_id, blendfile_id, name, type) values (?,?,?,?,?)", [scId, newId, bfElementId, scName, scName[0:2]], ) for block in bf.FindBlendFileBlocksWithCode("IM"): scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 scName = block.Get("id.name") liName = block.Get("name") liName = liName.split("\0")[0] liFilename = liName liName = determineProductionLocation(productionDir, file, liName) if liName != None and liName != "" and (not liName.endswith("Untitled")) and liName != "Render Result": connection.execute( "insert into element (id, file_id, blendfile_id, name, type, li_name, li_filename) values (?,?,?,?,?,?,?)", [scId, newId, bfElementId, scName, scName[0:2], liName, liFilename], ) libref = dict() for block in bf.FindBlendFileBlocksWithCode("LI"): scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 liOldAddress = block.OldAddress libref[liOldAddress] = scId scName = block.Get("id.name") liName = block.Get("name") liName = determineProductionLocation(productionDir, file, liName) liFilename = block.Get("filename") # absolute path when saved? if liFilename == None: # in blender 2.5 filename has been renamed to filepath liFilename = block.Get("filepath") # absolute path when saved? connection.execute( "insert into element (id, file_id, blendfile_id, name, type, li_name, li_filename) values (?,?,?,?,?,?,?)", [scId, newId, bfElementId, scName, scName[0:2], liName, liFilename], ) for block in bf.FindBlendFileBlocksWithCode("ID"): scId = firstElementId + offsetElementId offsetElementId = offsetElementId + 1 scName = block.Get("name") liOldAddress = block.Get("lib") liId = libref[liOldAddress] connection.execute( "insert into element (id, file_id, blendfile_id, name, type, library_id) values (?,?,?,?,?,?)", [scId, newId, bfElementId, scName, "ID", liId], ) connection.execute( "insert into element (id, file_id, type, bf_current_scene_id, bf_version, bf_pointersize, bf_littleendian, bf_compressed) values (?,?,?,?,?,?,?,?)", [bfElementId, newId, "BF", bfCurrentSceneId, bfVersion, bfPointerSize, bfLittleEndianness, bfCompressed], ) bf.close()