예제 #1
0
def handleStartSolveMissingLink(wfile, request, session):
    productionId=int(session["production_id"])
    production = indexer.getProduction(productionId)
    fileId=int(request["file_id"])
    elementId=int(request["element_id"])
    #determine original file if from elementid
    elementDetails = indexer.getElement(elementId)
    elementType=elementDetails[indexer.INDEX_ELEMENT_TYPE]
    orFileId = elementDetails[indexer.INDEX_ELEMENT_FILE_ID]
    orFileDetails = indexer.getFile(orFileId)
    tasks = []

    if elementType=='ID':
        newElementId=fileId
        newElementDetails=indexer.getElement(newElementId)
        cl = ChangeIDElement()
        cl.fileDetails = orFileDetails
        cl.fileId = orFileId
        cl.productionDetails = production
        cl.libraryDetails=indexer.getElement(elementDetails[indexer.INDEX_LIBRARY_ID])
        cl.elementDetails=elementDetails
        cl.newElementName=newElementDetails[indexer.INDEX_ELEMENT_NAME]
        tasks.append(cl)
    else:
        newFileDetails = indexer.getFile(fileId)
        cl = ChangeLibrary()
        cl.fileDetails = orFileDetails
        cl.fileId = orFileId
        cl.newFileDetails = newFileDetails
        cl.productionDetails = production
        cl.libraryDetails = elementDetails
        tasks.append(cl)
    
    session["tasks"]=tasks
    wfile.write("""[]""".encode())
예제 #2
0
def handleStartRenameElement(wfile, request, session):
    productionId = int(session["production_id"])
    production = indexer.getProduction(productionId)
    fileId = int(request["file_id"])
    elementId = int(request["element_id"])
    fileDetails = indexer.getFile(fileId)
    elementDetails = indexer.getElementDetails(elementId)
    newElementName = request["new_name"]

    for row in indexer.getFileElementByName(fileId, newElementName):
        wfile.write("""[{"message":"Element already exists."}]""".encode())
        return
    if newElementName[0:2] != elementDetails[2][0:2]:
        wfile.write(("""[{"message":"Type of element cannot be changed.[""" +
                     elementDetails[2][0:2] + """]"}]""").encode())
        return

    tasks = []
    filesDone = []
    usedby = indexer.getReferenceToElement(productionId, fileId,
                                           elementDetails[2])

    for used in usedby:
        ofileId = used[0]
        if ofileId not in filesDone:
            ac = RenameIDElement()
            ac.fileId = ofileId
            ac.fileDetails = indexer.getFile(ofileId)
            ac.elementDetails = elementDetails
            ac.referenceFileId = fileId
            ac.newElementName = newElementName
            ac.currentElementName = elementDetails[2]
            ac.currentFilename = fileDetails[2]
            ac.currentFileLocation = fileDetails[3]
            ac.productionDetails = production

            filesDone.append(ofileId)
            tasks.append(ac)

    bu = RenameElement()
    bu.fileId = fileId
    bu.fileDetails = fileDetails
    bu.elementDetails = elementDetails
    bu.currentFilename = fileDetails[2]
    bu.newElementName = newElementName
    bu.productionDetails = production
    tasks.append(bu)

    session["tasks"] = tasks
    wfile.write("""[]""".encode())
예제 #3
0
def handleStartRenameElement(wfile, request, session):
    productionId=int(session["production_id"])
    production = indexer.getProduction(productionId)
    fileId=int(request["file_id"])
    elementId=int(request["element_id"])
    fileDetails = indexer.getFile(fileId)
    elementDetails = indexer.getElementDetails(elementId)
    newElementName = request["new_name"]
    
    for row in indexer.getFileElementByName(fileId, newElementName): 
        wfile.write("""[{"message":"Element already exists."}]""".encode())
        return
    if newElementName[0:2] != elementDetails[2][0:2]:
        wfile.write(("""[{"message":"Type of element cannot be changed.["""+elementDetails[2][0:2]+"""]"}]""").encode())
        return
        
    
    tasks = []
    filesDone = []
    usedby = indexer.getReferenceToElement(productionId, fileId, elementDetails[2])
    
    for used in usedby:
        ofileId = used[0]
        if ofileId not in filesDone:
            ac = RenameIDElement()
            ac.fileId = ofileId
            ac.fileDetails = indexer.getFile(ofileId)
            ac.elementDetails = elementDetails
            ac.referenceFileId = fileId
            ac.newElementName = newElementName
            ac.currentElementName = elementDetails[2]
            ac.currentFilename = fileDetails[2]
            ac.currentFileLocation = fileDetails[3]
            ac.productionDetails=production

            filesDone.append(ofileId)
            tasks.append(ac)

    bu = RenameElement()
    bu.fileId = fileId
    bu.fileDetails = fileDetails
    bu.elementDetails = elementDetails
    bu.currentFilename = fileDetails[2]
    bu.newElementName = newElementName
    bu.productionDetails = production
    tasks.append(bu)
        
    session["tasks"]=tasks
    wfile.write("""[]""".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 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())
예제 #6
0
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())
예제 #7
0
def getAbsoluteFilename(productionId, fileId):
    """ determine the absolute path the given file
    input:
        productinoId - id of the production, the file is part of
        fileId - id of the file
    output:
        string - the absolute path
    """
    production = indexer.getProduction(productionId)
    pfile = indexer.getFile(fileId)
    return os.path.join(production[2], pfile[3])
예제 #8
0
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())
예제 #9
0
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())
예제 #10
0
def handleStartSolveMissingLink(wfile, request, session):
    productionId = int(session["production_id"])
    production = indexer.getProduction(productionId)
    fileId = int(request["file_id"])
    elementId = int(request["element_id"])
    #determine original file if from elementid
    elementDetails = indexer.getElement(elementId)
    elementType = elementDetails[indexer.INDEX_ELEMENT_TYPE]
    orFileId = elementDetails[indexer.INDEX_ELEMENT_FILE_ID]
    orFileDetails = indexer.getFile(orFileId)
    tasks = []

    if elementType == 'ID':
        newElementId = fileId
        newElementDetails = indexer.getElement(newElementId)
        cl = ChangeIDElement()
        cl.fileDetails = orFileDetails
        cl.fileId = orFileId
        cl.productionDetails = production
        cl.libraryDetails = indexer.getElement(
            elementDetails[indexer.INDEX_LIBRARY_ID])
        cl.elementDetails = elementDetails
        cl.newElementName = newElementDetails[indexer.INDEX_ELEMENT_NAME]
        tasks.append(cl)
    else:
        newFileDetails = indexer.getFile(fileId)
        cl = ChangeLibrary()
        cl.fileDetails = orFileDetails
        cl.fileId = orFileId
        cl.newFileDetails = newFileDetails
        cl.productionDetails = production
        cl.libraryDetails = elementDetails
        tasks.append(cl)

    session["tasks"] = tasks
    wfile.write("""[]""".encode())
def handleSvnRevert(wfile, request, session):
    file_id = request["file_id"]
    file_path = request["file_location"]
    revertAll = request["revert_all"]
    production_id = request["production_id"]
    production_result = indexer.getProduction(production_id)
    production_path = production_result[2]
    if file_id==None and file_path==None and revertAll:
        svn.svnRevert(production_path, revertAll)
    elif file_id!=None and not revertAll:
        result = indexer.getFile(file_id)
        rel_file_path = result[3]
        location = path.join(production_path, rel_file_path)
        svn.svnRevert(location)
    elif file_path!=None and not revertAll:
        rel_file_path = file_path
        location = path.join(production_path, rel_file_path)
        svn.svnRevert(location)
    wfile.write("[]\r\n".encode());
    return
def handleSvnAdd(wfile, request, session):
    file_id = request["file_id"]
    production_id = request["production_id"]
    file_location = request["file_location"]
    addAll = request["add_all"]
    if file_id!=-1:
        result = indexer.getFile(file_id)
        file_name = result[2]
        rel_file_path = result[3]
        production_result = indexer.getProduction(production_id)
        production_path = production_result[2]
        location = path.join(production_path, rel_file_path)
        svn.svnAdd(location)
    else:
        production_result = indexer.getProduction(production_id)
        production_path = production_result[2]
        location = path.join(production_path, file_location)
        svn.svnAdd(location)
    wfile.write("[]\r\n".encode());
    return
예제 #13
0
def handleSvnRevert(wfile, request, session):
    file_id = request["file_id"]
    file_path = request["file_location"]
    revertAll = request["revert_all"]
    production_id = request["production_id"]
    production_result = indexer.getProduction(production_id)
    production_path = production_result[2]
    if file_id == None and file_path == None and revertAll:
        svn.svnRevert(production_path, revertAll)
    elif file_id != None and not revertAll:
        result = indexer.getFile(file_id)
        rel_file_path = result[3]
        location = path.join(production_path, rel_file_path)
        svn.svnRevert(location)
    elif file_path != None and not revertAll:
        rel_file_path = file_path
        location = path.join(production_path, rel_file_path)
        svn.svnRevert(location)
    wfile.write("[]\r\n".encode())
    return
예제 #14
0
def handleSvnAdd(wfile, request, session):
    file_id = request["file_id"]
    production_id = request["production_id"]
    file_location = request["file_location"]
    addAll = request["add_all"]
    if file_id != -1:
        result = indexer.getFile(file_id)
        file_name = result[2]
        rel_file_path = result[3]
        production_result = indexer.getProduction(production_id)
        production_path = production_result[2]
        location = path.join(production_path, rel_file_path)
        svn.svnAdd(location)
    else:
        production_result = indexer.getProduction(production_id)
        production_path = production_result[2]
        location = path.join(production_path, file_location)
        svn.svnAdd(location)
    wfile.write("[]\r\n".encode())
    return
예제 #15
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())