Beispiel #1
0
def main(argv=None):
    success = True
    name = ''
    if not arcpy.Exists(gzSupport.workspace):
        gzSupport.addMessage(gzSupport.workspace +
                             " does not exist, attempting to create")
        gzSupport.createGizintaGeodatabase()
    else:
        gzSupport.compressGDB(gzSupport.workspace)
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    try:
        gzSupport.addMessage("Looking for drawings modified since " + since)
        minTime = datetime.datetime.strptime(since, "%d/%m/%Y %I:%M:%S %p")
        cadFiles = gzSupport.getFileList(cadFolder, cadExt, minTime)
        if len(cadFiles) > 0:
            progBar = len(cadFiles) + 1
            arcpy.SetProgressor("step", "Importing Drawings...", 0, progBar, 1)
            arcpy.SetProgressorPosition()
            gzSupport.deleteExistingRows(datasets)
        for item in cadFiles:
            cadPath = item[0]
            cadName = item[1]
            gzSupport.addMessage("Importing Drawing " + cadName)

            for dataset in datasets:
                try:
                    name = dataset.getAttributeNode("sourceName").nodeValue
                except:
                    name = dataset.getAttributeNode("name").nodeValue

                gzSupport.sourceIDField = dataset.getAttributeNode(
                    "sourceIDField").nodeValue
                xmlFields = gzSupport.getXmlElements(gzSupport.xmlFileName,
                                                     "Field")
                arcpy.SetProgressorLabel("Loading " + name + " for " +
                                         cadName + "...")
                arcpy.env.Workspace = gzSupport.workspace
                targetName = dataset.getAttributeNode("targetName").nodeValue
                sourceWorkspace = os.path.join(cadPath, cadName)
                exists = False
                if not arcpy.Exists(
                        os.path.join(gzSupport.workspace, targetName)):
                    gzSupport.addMessage(
                        os.path.join(gzSupport.workspace, targetName) +
                        " does not exist")
                else:
                    exists = True
                    #arcpy.Delete_management(os.path.join(gzSupport.workspace,targetName))

                try:
                    if not exists == True:
                        retVal = gzSupport.exportDataset(
                            sourceWorkspace, name, targetName, dataset,
                            xmlFields)
                        addDrawingField(
                            os.path.join(gzSupport.workspace, targetName),
                            cadName)
                    else:
                        retVal = importLayer(cadPath, cadName, dataset)
                        addDrawingField(
                            os.path.join(gzSupport.workspace, targetName),
                            cadName)
                    if retVal == False:
                        success = False
                except:
                    gzSupport.showTraceback()
                    success = False
                    retVal = False

                arcpy.env.Workspace = gzSupport.workspace
                gzSupport.logDatasetProcess(cadName, name, retVal)
                gzSupport.cleanupGarbage()
            arcpy.SetProgressorPosition()
    except:
        gzSupport.addError("A Fatal Error occurred")
        gzSupport.showTraceback()
        success = False
        gzSupport.logDatasetProcess("extractCADToGDB", name, False)
    finally:
        arcpy.ResetProgressor()
        arcpy.RefreshCatalog(gzSupport.workspace)
        arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
        gzSupport.cleanupGarbage()

    if success == False:
        gzSupport.addError(
            "Errors occurred during process, look in log files for more information"
        )
    if gzSupport.ignoreErrors == True:
        success = True
    gzSupport.closeLog()
    arcpy.SetParameter(SUCCESS, success)
Beispiel #2
0
def main(argv=None):
    success = True
    if not arcpy.Exists(gzSupport.workspace):
        gzSupport.addMessage(gzSupport.workspace + " does not exist, attempting to create")
        gzSupport.createGizintaGeodatabase()
    else:
        gzSupport.compressGDB(gzSupport.workspace)
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    try:
        gzSupport.addMessage("Looking for drawings modified since " + since)
        minTime = datetime.datetime.strptime(since, "%d/%m/%Y %I:%M:%S %p")
        cadFiles = gzSupport.getFileList(cadFolder, cadExt, minTime)
        if len(cadFiles) > 0:
            progBar = len(cadFiles) + 1
            arcpy.SetProgressor("step", "Importing Drawings...", 0, progBar, 1)
            arcpy.SetProgressorPosition()
            gzSupport.deleteExistingRows(datasets)
        for item in cadFiles:
            cadPath = item[0]
            cadName = item[1]
            gzSupport.addMessage("Importing Drawing " + cadName)

            for dataset in datasets:
                try:
                    name = dataset.getAttributeNode("sourceName").nodeValue
                except:
                    name = dataset.getAttributeNode("name").nodeValue

                gzSupport.sourceIDField = dataset.getAttributeNode("sourceIDField").nodeValue
                xmlFields = gzSupport.getXmlElements(gzSupport.xmlFileName, "Field")
                arcpy.SetProgressorLabel("Loading " + name + " for " + cadName + "...")
                arcpy.env.Workspace = gzSupport.workspace
                targetName = dataset.getAttributeNode("targetName").nodeValue
                sourceWorkspace = os.path.join(cadPath, cadName)
                exists = False
                if not arcpy.Exists(os.path.join(gzSupport.workspace, targetName)):
                    gzSupport.addMessage(os.path.join(gzSupport.workspace, targetName) + " does not exist")
                else:
                    exists = True
                    # arcpy.Delete_management(os.path.join(gzSupport.workspace,targetName))

                try:
                    if not exists == True:
                        retVal = gzSupport.exportDataset(sourceWorkspace, name, targetName, dataset, xmlFields)
                        addDrawingField(os.path.join(gzSupport.workspace, targetName), cadName)
                    else:
                        retVal = importLayer(cadPath, cadName, dataset)
                        addDrawingField(os.path.join(gzSupport.workspace, targetName), cadName)
                    if retVal == False:
                        success = False
                except:
                    gzSupport.showTraceback()
                    success = False
                    retVal = False

                arcpy.env.Workspace = gzSupport.workspace
                gzSupport.logDatasetProcess(cadName, name, retVal)
                gzSupport.cleanupGarbage()
            arcpy.SetProgressorPosition()
    except:
        gzSupport.addError("A Fatal Error occurred")
        gzSupport.showTraceback()
        success = False
        gzSupport.logDatasetProcess("", "", False)
    finally:
        arcpy.ResetProgressor()
        arcpy.RefreshCatalog(gzSupport.workspace)
        arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
        gzSupport.cleanupGarbage()

    if success == False:
        gzSupport.addError("Errors occurred during process, look in log files for more information")
    if gzSupport.ignoreErrors == True:
        success = True
    gzSupport.closeLog()
    arcpy.SetParameter(SUCCESS, success)
Beispiel #3
0
def main(argv = None):
    # process one or more drawings
    global log, playlists_xml, playlists
    outputSuccess = True # default value, will be set to False if any processing errors returned
    doImports()
    processed = 0
    errorCount = 0
    cfgfile = fixServerConfigPath(gseData_xml)
    xmlDataDoc = xml.dom.minidom.parse(cfgfile)
    gseData = gseDataSettings(xmlDataDoc)
    gss = []
    for playlist in playlists_xml:
        filepath = fixConfigPath(playlist)
        playlists.append(filepath)
        xmlDoc = xml.dom.minidom.parse(filepath)
        gsClass = gseSettings(xmlDoc,gseData)
        gss.append(gsClass)
        
    tm = time.strftime("%Y%m%d%H%M%S")
    
    logFile = gss[0].logFileName.replace('.log','_' + tm + '.log')
    log = open(logFile,'w')
    autoSync = gss[0].autoSync
    exitOnError = gss[0].exitOnError
        
    try:
        totalTime = gzSupport.timer(0)
        inputFiles = gzSupport.getFileList(gss[0].cadFolder,gss[0].fileExt,gss[0].minTime)

        for fileFound in inputFiles:
            if errorCount > 0 and exitOnError == True:
                break
            folder = fileFound[0]
            dwg = fileFound[1]
            cadFile = os.path.join(folder,dwg)
            drawingTime = gzSupport.timer(0)
            pVal = 0 # counter for playlist looping
            partFailed = False
            if(dwg.find(gss[pVal].nameContains) > -1) and os.path.exists(cadFile):
                msg("\n" + dwg)
                for playlist in playlists: # Loop through the playlists and do the loading from CAD
                    if cont(errorCount,exitOnError,partFailed): # stop processing if any errors or continue if exit on error param is false
                        retVal = doLoad(playlist,folder,dwg,gss[pVal]) # Load the playlist using FME subprocess
                        if(retVal != True):
                            outputSuccess = False
                            errorCount += 1
                            gss[pVal].loaded = False
                            partFailed = True
                        else:
                            gss[pVal].loaded = True
                    pVal += 1
                if cont(errorCount,exitOnError,partFailed):
                    pVal = 0
                    if partFailed == False and autoSync == True: # Sync is param set and no errors have been returned
                        retVal = doSync(playlists,folder,dwg,gss[pVal]) # sync from Staging to Production
                        if(retVal != True):
                            outputSuccess = False
                            errorCount += 1
                        else:
                            for playlist in playlists: # go back through the playlists and Sync for this drawing
                                gss[pVal].syncd = True
                                pVal += 1
                loaded = False
                for gs in gss:
                    if (gs.loaded == True or gs.syncd == True) and dwg.find(gs.nameContains) > -1: # if any load or sync processing happened...
                        loaded = True
                if loaded == True:
                    msg(dwg + " total processing time: " + getTimeElapsed(drawingTime))
                    processed += 1
                    if gss[0].deleteCADFiles == True and partFailed == False:
                        try:
                            gzSupport.cleanupGarbage()
                            os.remove(cadFile)
                            try:
                                os.remove(cadFile[:len(cadFile)-4]+'.wld')
                            except:
                                pass
                            msg(cadFile + " deleted")
                        except:
                            msg("Unable to delete CAD file " + cadFile + "... continuing")
                if processed % 10 == 0:
                    msg("Processed " + str(processed))
                gzSupport.cleanupGarbage()
    except:
        errorCount += 1
        msg("A fatal error was encountered in gseLoaderFME.py")
        gzSupport.showTraceback()
        outputSuccess = False
        logProcess("gseLoaderFME","drawings",outputSuccess,gss[0].stagingWS)

    finally:
        arcpy.SetParameterAsText(successParam,outputSuccess)
        msg("\nTotal Number of Errors = " + str(errorCount))
        msg("outputSuccess set to: " + str(outputSuccess))
        msg(str(processed) + " drawings processed")
        msg("Total Processing time: " + getTimeElapsed(totalTime) + "\n")
        del gss, playlists
        log.close()