def doSync(playlists,folder,dwg,gs): # Sync process drawing global log inputDrawing = os.path.join(folder,dwg) drawingTime = gzSupport.timer(0) msg("Sync changes to database for " + dwg) # sync changes try: #result = arcpy.gseSyncChanges_gse(inputDrawing," ".join(playlists),gs.stagingWS,gs.productionWS) # the arcpy approach caused issues so a direct sync call has turned out to be more reliable... retVal = gseSyncChanges.sync(inputDrawing," ".join(playlists),gs.stagingWS,gs.productionWS,log) except: msg("Error encountered, sync failed...") retVal = False logProcess("Sync to Production",dwg,retVal,gs.productionWS) msg(dwg + " Sync processing time: " + getTimeElapsed(drawingTime) ) del inputDrawing gzSupport.cleanupGarbage() if retVal == False: msg("return value set to: " + str(retVal)) return retVal
def doLoad(playlist_xml,folder,dwg,gs): # Load process drawing global log outputSuccess = False # default value inputDrawing = os.path.join(folder,dwg) drawingTime = gzSupport.timer(0) msg("\nLoading " + dwg + " to database") # load using FME if gs.fmeLoadFile == None or gs.fmeLoadFile == "" or gs.fmeLoadFile == gse.fmeFolder: msg("No FME file for loading") retVal = True else: retVal = gseRunFME.load(inputDrawing,gs.fmeExe,gs.fmeLoadFile,gs.stagingWS,gs.productionWS,gs.sourceEPSG,gs.runas,gs.truncate,playlist_xml,gs.source, getFeatureTypes(playlist_xml,"sourceName"),getFeatureTypes(playlist_xml,"targetName")) msg("FME processing time: " + getTimeElapsed(drawingTime)) logProcess(gs.fmeLoadFile[:gs.fmeLoadFile.rfind(os.sep)+1],dwg,retVal,gs.stagingWS) msg(dwg + " Load processing time: " + getTimeElapsed(drawingTime) ) gzSupport.cleanupGarbage() if retVal == False: msg("return value set to: " + str(retVal)) return retVal
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()
def getTimeElapsed(timeVal): # format elapsed time string return (str(int(gzSupport.timer(timeVal)/60)) + 'm' + str(int(gzSupport.timer(timeVal) % 60)) + 's')