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())
Exemplo n.º 3
0
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())
Exemplo n.º 4
0
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())