def handleGetFileView(wfile, request, session): """Service to retrieve all file level information being: production file elements of the file references of the file used by of the file """ productionId=int(request["production_id"]) fileId=int(request["file_id"]) indexer.updateIndex(productionId) production = indexer.getProduction(productionId) file = indexer.getFileDetails(fileId) elements = indexer.getFileElements(fileId) references = indexer.getFileReferences(fileId) usedby = indexer.getFileUsedBy(fileId) result = [] result.append(productionToObject(production)) if file != None: result.append(fileDetailToObject(file)) else: file=indexer.getFile(fileId) result.append(fileToObject(file)) result.append(elementsToObject(elements)) result.append(referencesToObject(references)) result.append(usedbysToObject(usedby)) wfile.write(json.dumps(result).encode())
def handleGetFileView(wfile, request, session): """Service to retrieve all file level information being: production file elements of the file references of the file used by of the file """ productionId = int(request["production_id"]) fileId = int(request["file_id"]) indexer.updateIndex(productionId) production = indexer.getProduction(productionId) file = indexer.getFileDetails(fileId) elements = indexer.getFileElements(fileId) references = indexer.getFileReferences(fileId) usedby = indexer.getFileUsedBy(fileId) result = [] result.append(productionToObject(production)) if file != None: result.append(fileDetailToObject(file)) else: file = indexer.getFile(fileId) result.append(fileToObject(file)) result.append(elementsToObject(elements)) result.append(referencesToObject(references)) result.append(usedbysToObject(usedby)) wfile.write(json.dumps(result).encode())
def handleStartRenameDirectory(wfile, request, session): productionId=int(request["production_id"]) production=indexer.getProduction(productionId) sourceDirectory=str(request["source_directory"]) targetLastDirectoryName=str(request["target_directory_name"]) targetDirectory = os.path.join(os.path.dirname(sourceDirectory), targetLastDirectoryName) targetAbsoluteDirectory = os.path.join(production[indexer.INDEX_PRODUCTION_LOCATION], targetDirectory) files = indexer.getProductionFiles(productionId); #perform checks if (sourceDirectory==targetDirectory): wfile.write("""[{"message":"Target directory is same as source."}]""".encode()) return; if (os.path.exists(targetAbsoluteDirectory)): wfile.write("""[{"message":"Target directory already exists."}]""".encode()) return; filesInside = [] tasks=[] for file in files: if file[indexer.INDEX_FILE_LOCATION].startswith(sourceDirectory): filesInside.append(file) referencesOutside = {} for file in filesInside: referencesFromOutside = indexer.getFileUsedBy(file[indexer.INDEX_FILE_ID]) for reference in referencesFromOutside: referenceFile = indexer.getFile(reference[indexer.INDEX_REFERENCE_FILE_ID]) if not referenceFile[indexer.INDEX_FILE_LOCATION].startswith(sourceDirectory): if referenceFile not in referencesOutside.keys(): referencesOutside[referenceFile]=[] if file not in referencesOutside[referenceFile]: referencesOutside[referenceFile].append(file) for referenceFile in referencesOutside.keys(): for file in referencesOutside[referenceFile]: ac = ChangeReference() ac.fileId = referenceFile[indexer.INDEX_FILE_ID] ac.fileDetails = referenceFile ac.referenceFileId = file[indexer.INDEX_FILE_ID] ac.newLocation = os.path.dirname(file[indexer.INDEX_FILE_LOCATION].replace(sourceDirectory, targetDirectory, 1)) ac.currentFilename = file[indexer.INDEX_FILE_NAME] ac.currentFileLocation = file[indexer.INDEX_FILE_LOCATION] ac.productionDetails=production tasks.append(ac) renameDir = RenameDirectory() renameDir.productionDetails=production renameDir.sourceDirectory = sourceDirectory renameDir.targetDirectory = targetDirectory tasks.append(renameDir) session["tasks"]=tasks if wfile != None: wfile.write("""[]""".encode())
def handleStartRenameFile(wfile, request, session): productionId = int(session["production_id"]) production = indexer.getProduction(productionId) fileId = int(request["file_id"]) fileDetails = indexer.getFile(fileId) newFilename = request["new_filename"] if os.path.exists( os.path.join( os.path.dirname(os.path.join(production[2], fileDetails[3])), newFilename)): wfile.write("""[{"message":"File already exists."}]""".encode()) return tasks = [] filesDone = [] usedby = indexer.getFileUsedBy(fileId) for used in usedby: ofileId = used[3] if ofileId not in filesDone: ac = RenameLibrary() ac.fileId = ofileId ac.fileDetails = indexer.getFile(ofileId) ac.referenceFileId = fileId ac.newFilename = newFilename ac.currentFilename = fileDetails[2] ac.currentFileLocation = fileDetails[3] ac.productionDetails = production filesDone.append(ofileId) tasks.append(ac) bu = RenameFile() bu.fileId = fileId bu.fileDetails = fileDetails bu.currentFilename = fileDetails[2] bu.newFilename = newFilename bu.productionDetails = production tasks.append(bu) session["tasks"] = tasks wfile.write("""[]""".encode())
def handleStartMoveFile(wfile, request, session): productionId=int(session["production_id"]) production = indexer.getProduction(productionId) fileId=int(request["file_id"]) fileDetails = indexer.getFile(fileId) newLocation = request["new_location"] if os.path.exists(os.path.join(production[2],newLocation,fileDetails[2])): wfile.write("""[{"message":"File already exists."}]""".encode()) return tasks = [] filesDone = [] usedby = indexer.getFileUsedBy(fileId) for used in usedby: ofileId = used[3] if ofileId not in filesDone: ac = ChangeReference() ac.fileId = ofileId ac.fileDetails = indexer.getFile(ofileId) ac.referenceFileId = fileId ac.newLocation = newLocation ac.currentFilename = fileDetails[2] ac.currentFileLocation = fileDetails[3] ac.productionDetails=production filesDone.append(ofileId) tasks.append(ac) bu = MoveFile() bu.fileId = fileId bu.fileDetails = fileDetails bu.currentFilename = fileDetails[2] bu.currentFileLocation = fileDetails[3] bu.newLocation = newLocation bu.productionDetails=production tasks.append(bu) session["tasks"]=tasks wfile.write("""[]""".encode())
def handleStartMoveDirectory(wfile, request, session): productionId = int(request["production_id"]) production = indexer.getProduction(productionId) sourceDirectory = str(request["source_directory"]) targetDirectory = str(request["target_directory"]) targetAbsoluteDirectory = os.path.join( production[indexer.INDEX_PRODUCTION_LOCATION], targetDirectory) #perform checks if (sourceDirectory == targetDirectory): wfile.write( """[{"message":"Target directory is same as source."}]""".encode()) return if (os.path.exists(targetAbsoluteDirectory)): wfile.write( """[{"message":"Target directory already exists."}]""".encode()) return files = indexer.getProductionFiles(productionId) filesInside = [] tasks = [] for file in files: if file[indexer.INDEX_FILE_LOCATION].startswith(sourceDirectory): filesInside.append(file) referencesOutside = {} for file in filesInside: referencesFromOutside = indexer.getFileUsedBy( file[indexer.INDEX_FILE_ID]) for reference in referencesFromOutside: referenceFile = indexer.getFile( reference[indexer.INDEX_REFERENCE_FILE_ID]) if not referenceFile[indexer.INDEX_FILE_LOCATION].startswith( sourceDirectory): if referenceFile not in referencesOutside.keys(): referencesOutside[referenceFile] = [] if file not in referencesOutside[referenceFile]: referencesOutside[referenceFile].append(file) for referenceFile in referencesOutside.keys(): for file in referencesOutside[referenceFile]: ac = ChangeReference() ac.fileId = referenceFile[indexer.INDEX_FILE_ID] ac.fileDetails = referenceFile ac.referenceFileId = file[indexer.INDEX_FILE_ID] ac.newLocation = os.path.dirname( file[indexer.INDEX_FILE_LOCATION].replace( sourceDirectory, targetDirectory, 1)) ac.currentFilename = file[indexer.INDEX_FILE_NAME] ac.currentFileLocation = file[indexer.INDEX_FILE_LOCATION] ac.productionDetails = production tasks.append(ac) referencesInside = {} for file in filesInside: referencesFromInside = indexer.getFileReferences( file[indexer.INDEX_FILE_ID]) for reference in referencesFromInside: referenceFile = indexer.getFile( reference[indexer.INDEX_REFERENCE_FILE_ID]) if referenceFile != None and not referenceFile[ indexer.INDEX_FILE_LOCATION].startswith(sourceDirectory): if referenceFile not in referencesInside.keys(): referencesInside[referenceFile] = [] if file not in referencesInside[referenceFile]: referencesInside[referenceFile].append(file) for referenceFile in referencesInside.keys(): for file in referencesInside[referenceFile]: ac = ChangeReferenceForMove() ac.fileId = file[indexer.INDEX_FILE_ID] ac.fileDetails = file ac.referenceFileDetails = referenceFile ac.referenceFileId = referenceFile[indexer.INDEX_FILE_ID] ac.targetDirectory = targetDirectory ac.sourceDirectory = sourceDirectory ac.currentFilename = file[indexer.INDEX_FILE_NAME] ac.currentFileLocation = file[indexer.INDEX_FILE_LOCATION] ac.productionDetails = production tasks.append(ac) moveDir = MoveDirectory() moveDir.productionDetails = production moveDir.sourceDirectory = sourceDirectory moveDir.targetDirectory = targetDirectory tasks.append(moveDir) session["tasks"] = tasks if wfile != None: wfile.write("""[]""".encode())