def rebuildindexes(self): # https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/rebuild-indexes.htm return self.interpret( arcpy.RebuildIndexes_management(self.gdb.sdeconn, 'NO_SYSTEM', self.name, 'ALL'))
def compress_rebuild_analyze(): try: log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") + "Compressing database...\n") arcpy.Compress_management(WORKSPACE_SDE) log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") + "Rebuilding indexes...\n") arcpy.RebuildIndexes_management(WORKSPACE_SDE, "SYSTEM") log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") + "Analyzing datasets...\n") arcpy.AnalyzeDatasets_management(WORKSPACE_SDE, "SYSTEM") except Exception: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = datetime.datetime.now().strftime( "%H:%M:%S %m/%d/%Y " ) + "An error has occured.\nTraceback info:\n" + tbinfo + "Error Info:\n" + " " + str( sys.exc_info()[1]) if arcpy.GetMessages(2) != "": msgs = "\n\n-ARCPY ERRORS-\n" + arcpy.GetMessages( 2) + "\n\nScript finished with errors." else: msgs = "\n\nScript finished with errors." log.write(pymsg) log.write(msgs) log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") + "Script failed. Recreating versions...\n") recreate_versions() log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") + "Reaccepting connections...\n") clean_up()
def rebuildindexes(self): # https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/manage-oracle/rebuild-system-table-indexes.htm output = 0 if self.isadministrator(): return self.interpret( arcpy.RebuildIndexes_management(self.sdeconn, 'SYSTEM', '', 'ALL')) return output
def recalc_indexes(conn_string, fc_target_fullnamewdb): ##print ("Entering Recalcaulte Indexes----") print(" Indexing: {0}".format(fc_target_fullnamewdb)) try: arcpy.RebuildIndexes_management(conn_string, "NO_SYSTEM", fc_target_fullnamewdb, "ALL") print(" --Status: Success!\n") except Exception as error_indexes: print(" --Status: Failure!\n") print(error_indexes.args[0]) ##print ("----Leaving Recalcaulte Indexes") return
def rebuildIndexes(self): self.current_item += 1 self.itemPrint() # ↓ try: arcpy.RebuildIndexes_management(self.sde_connection, "SYSTEM", "", "ALL") self.itemPrint() # ↑ maintenance_log.appendToFile([ self.maintenance_item[self.current_item], self.maintenance_status[1] ]) except Exception as e: self.handleException(e)
def RebuildGisIndexes(Connections): ''' This function takes Geodatabase connections as inputs (in the form of a list) and rebuilds the indexes for all ESRI registered tables in the database. ''' for Connection in Connections: env.workspace = Connection arcpy.Compress_management(Connection) print Connection + " was compressed" DataList = arcpy.ListTables() + arcpy.ListFeatureClasses() GisDataList = [] for item in DataList: # Exclude non-ESRI tables from having indexes updated if 'DBO' in item: GisDataList.append(item) arcpy.RebuildIndexes_management(Connection, "SYSTEM", GisDataList, "ALL") arcpy.AnalyzeDatasets_management(Connection, "SYSTEM", GisDataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") print "Indexes and statistics for GIS tables in " + Connection + " have been rebuilt" print "Script ran successfully"
acquire_locks="LOCK_AQUIRED", abort_if_conflicts="NO_ABORT", conflict_definition="BY_OBJECT", conflict_resolution="FAVOR_TARGET_VERSION", with_post="POST", with_delete="KEEP_VERSION", out_log=os.path.join(file_loc, 'reconcile_log')) # Compress database and reopen to outside connections logging.info('Compressing database...') arcpy.Compress_management(SDE) arcpy.AcceptConnections(SDE, True) logging.debug('Open to connections') except: print("There was an error!") logging.error( "An error has occured while reconciling and compressing versions", exc_info=True) arcpy.AcceptConnections(SDE, True) # Rebuild indexes and update statistics try: logging.info("Rebuilding indexes...") arcpy.RebuildIndexes_management(SDE, "SYSTEM") logging.info("Updating statistics") arcpy.AnalyzeDatasets_management(SDE, "SYSTEM") except: logging.error( "An error has occured while rebuilding indexes and updating statistics.", exc_info=True) logging.info("SCRIPT COMPLETE")
# Get a list of versions to pass into the ReconcileVersions tool. versionList = arcpy.ListVersions('Database Connections/[email protected]_EGDB_20170105A.sde') # Execute the ReconcileVersions tool. arcpy.ReconcileVersions_management('Database Connections/[email protected]_EGDB_20170105A.sde', "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "ABORT_CONFLICTS", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION", r"C:/Users/daniel.scott/Desktop/log.txt") # Compress database arcpy.Compress_management(workspace) print 'Compression Complete' # Get a list of stand alone feature classes dataList = arcpy.ListFeatureClasses() # Add Feature classes in datasets for dataset in arcpy.ListDatasets("", "Feature"): arcpy.env.workspace = os.path.join(workspace, dataset) dataList += arcpy.ListFeatureClasses() # reset the workspace arcpy.env.workspace = workspace # Execute rebuild indexes arcpy.RebuildIndexes_management(workspace, "SYSTEM", dataList, "ALL") print 'Rebuild Complete' # Execute analyse indexes arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") print 'Analyze complete' # Allow connections. arcpy.AcceptConnections(workspace, True)
# Run the compress tool. try: print("Running compress") arcpy.Compress_management(adminConn) #if the compress is successful add a message. compressMsg = '\nCompress was successful.\n\r' except: #If the compress failed, add a message. compressMsg = '\nCompress failed: error message below.\n\r' + arcpy.GetMessages( ) #Update statistics and idexes for the system tables # Note: to use the "SYSTEM" option the user must be an geodatabase or database administrator. try: print("Rebuilding indexes on the system tables") arcpy.RebuildIndexes_management(adminConn, "SYSTEM") rebuildSystemMsg = 'Rebuilding of system table indexes successful.\n\r' except: rebuildSystemMsg = 'Rebuild indexes on system tables fail: error message below.\n\r' + arcpy.GetMessages( ) try: print("Updating statistics on the system tables") arcpy.AnalyzeDatasets_management(adminConn, "SYSTEM") analyzeSystemMsg = 'Analyzing of system tables successful.\n\r' except: analyzeSystemMsg = 'Analyze system tables failed: error message below.\n\r' + arcpy.GetMessages( ) # Allow connections again. print("Allow users to connect to the database again")
if len(verReconcileList) > 0: # Execute the ReconcileVersions tool. # Put log in a better place in the future arcpy.ReconcileVersions_management(TIworkspace, "ALL_VERSIONS", TItargetVersion, verReconcileList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "KEEP_VERSION", "c:/temp/reconcilelog.txt") # Run the compress tool. arcpy.Compress_management(TIworkspace) # Rebuild indexes and analyze the states and states_lineages system tables arcpy.RebuildIndexes_management(TIworkspace, "SYSTEM", "", "ALL") arcpy.AnalyzeDatasets_management(TIworkspace, "SYSTEM", "", "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") ''' ********************* Data Owner(s) Section ********************* ''' # Get a list of datasets owned by the data owner user (requires second connection file) # Get the user name for the workspace # this assumes you are using database authentication. # OS authentication connection files do not have a 'user' property. userName = userList
except: write_log("Unable to sleep", log) # =================== ======== ======================================================================================= ========== # #Analyse system tables## # =================== ======== ======================================================================================= ========== # Analyze system tables try: write_log( "-----------------------------------------------------------", log) write_log("REBUILDING INDEXES (SYSTEM TABLES)", log) write_log( "-----------------------------------------------------------", log) write_log("Rebuilding indexes on system tables ...", log) try: arcpy.RebuildIndexes_management(SDEconnection, "SYSTEM") write_log( "\t Rebuilding of system table indexes successful." + arcpy.GetMessages(), log) except: rebuildSystemMsg = 'Rebuild indexes on system tables fail: error message below.\n\r' + arcpy.GetMessages( ) write_log("\t \t" + rebuildSystemMsg, log) except: # Allow the database to begin accepting connections again arcpy.AcceptConnections(SDEconnection, True) # Allow the database to begin accepting connections again arcpy.AcceptConnections(SDEconnection, True) # =================== ======== ======================================================================================= ==========
# Step for updating the data # --------------------------------- import arcpy mylayer = 'MylayerName' arcpy.MakeFeatureLayer_management(shp_path, mylayer, 'someParamsField > 100') for i in xrange(0, arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) arcpy.Append_management(mylayer, target_layer, 'NO_TEST') for i in xrange(0, arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) arcpy.RebuildIndexes_management(work_db, '#', [target_layer_name]) for i in xrange(0, arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) # starting service folderURL = "/arcgis/admin/services/{}/start".format(service) params = urllib.urlencode({'token': token, 'f': 'json'}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} httpConn = httplib.HTTPSConnection(ags_server) httpConn.request("POST", folderURL, params, headers) response = httpConn.getresponse() httpConn.close() print 'AGS start done' # ---------------------------------
for DB in adminDB: try: arcpy.env.workspace = AdminFileDir + DB userName = arcpy.Describe( arcpy.env.workspace).connectionProperties.user oDataList = arcpy.ListTables( '*.' + userName + '.*') + arcpy.ListFeatureClasses( '*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*') for dataset in arcpy.ListDatasets('*.' + userName + '.*'): oDataList += arcpy.ListFeatureClasses(feature_dataset=dataset) LogFile.write("Tables owned by " + userName + ":," + str(oDataList) + ",\n") arcpy.AddMessage("Rebuilding indexes for " + DB + "\n") LogFile.write("Rebuilding indexes for," + DB + "\n") arcpy.RebuildIndexes_management(arcpy.env.workspace, "NO_SYSTEM", oDataList, "ALL") arcpy.AddMessage("Analyzing data for " + DB + "\n") LogFile.write("Analyzing data for," + DB + "\n") arcpy.AnalyzeDatasets_management(arcpy.env.workspace, "NO_SYSTEM", oDataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") except arcpy.ExecuteError: msgs = arcpy.GetMessages(2) arcpy.AddError(msgs) arcpy.AddMessage(msgs) LogFile.write(msgs) ErrorCount = ErrorCount + 1 except: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(
#compress/rebuild/analyze SDE Databases import arcpy db='C:\SDEConnectionFiles\GIS\[email protected]' arcpy.env.workspace = 'C:\SDEConnectionFiles\GIS\[email protected]' ##arcpy.AcceptConnections(db, False) ##arcpy.DisconnectUser(db, "ALL") ##arcpy.Compress_management(db) ##Get a list of all the datasets the user has access to. ##First, get all the stand alone tables, feature classes and rasters owned by the current user. dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters() exceptions = [u'gis.transportation.bicyclecounts',u'gis.transportation.pedestriancounts',u'gis.transportation.trafficcounts',u'gis.transportation.lts_for_ruti',u'gis.transportation.tc_app'] data = set(dataList) - set(exceptions) d = list(data) ### Next, for feature datasets owned by the current user ### get all of the featureclasses and add them to the master list. ##for dataset in arcpy.ListDatasets(): ## dataList += arcpy.ListFeatureClasses(feature_dataset=dataset) arcpy.RebuildIndexes_management(db, "SYSTEM", d, "ALL") arcpy.AnalyzeDatasets_management(db, "SYSTEM", d, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") ## #arcpy.AcceptConnections(db, True)
indexlog = 'C:\Scripts_2016\Dans_Scripts\Log\CompressLog.txt' #name of log file # Rebuild indexes and analyze the states and states_lineages system tables datasetlist = arcpy.ListDatasets("", "Feature") analysels = [] for dataset in datasetlist: write_log( "-----------------------------------------------------------", indexlog) write_log( "starting to rebuild indexes for {0} + time started {1}".format( dataset, Time), indexlog) fclist = arcpy.ListFeatureClasses("*", "", dataset) for fc in fclist: analysels.append(fc) arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", dataset, "ALL") write_log("Indexes rebuilt for {0}".format(fc), indexlog) write_log( "-----------------------------------------------------------", indexlog) write_log("Indexing complete at {0}".format(Time), indexlog) write_log("-----------------------------------------------------------", indexlog) # Reset geoprocessing environment settings arcpy.ResetEnvironments() # Reset a specific environment setting arcpy.ClearEnvironment("workspace") #=================== ======== ======================================================================================= ========== ##ANALYSE##
def mainFunction( geodatabase ): # Get parameters from ArcGIS Desktop tool by seperating by comma e.g. (var1 is 1st parameter,var2 is 2nd parameter,var3 is 3rd parameter) try: # Log start if logInfo == "true": loggingFunction(logFile, "start", "") # --------------------------------------- Start of code --------------------------------------- # # Compress the geodatabase arcpy.AddMessage("Compressing the database....") arcpy.env.workspace = geodatabase arcpy.Compress_management(geodatabase) # Load in datsets to a list dataList = arcpy.ListTables() + arcpy.ListFeatureClasses( ) + arcpy.ListDatasets() # Load in datasets from feature datasets to the list for dataset in arcpy.ListDatasets("", "Feature"): arcpy.env.workspace = os.path.join(geodatabase, dataset) dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets() # Reset the workspace arcpy.env.workspace = geodatabase # Get the user name for the workspace userName = arcpy.Describe( geodatabase).connectionProperties.user.lower() # Remove any datasets that are not owned by the connected user. userDataList = [ ds for ds in dataList if ds.lower().find(".%s." % userName) > -1 ] # Execute analyze datasets arcpy.AddMessage("Analyzing and updating the database statistics....") # Note: to use the "SYSTEM" option the workspace user must be an administrator. arcpy.AnalyzeDatasets_management(geodatabase, "SYSTEM", userDataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") # Execute rebuild indexes arcpy.AddMessage( "Rebuilding the indexes for all tables in the database....") # Note: to use the "SYSTEM" option the workspace user must be an administrator. arcpy.RebuildIndexes_management(geodatabase, "SYSTEM", userDataList, "ALL") # --------------------------------------- End of code --------------------------------------- # # If called from gp tool return the arcpy parameter if __name__ == '__main__': # Return the output if there is any if output: arcpy.SetParameterAsText(1, output) # Otherwise return the result else: # Return the output if there is any if output: return output # Log start if logInfo == "true": loggingFunction(logFile, "end", "") pass # If arcpy error except arcpy.ExecuteError: # Show the message arcpy.AddError(arcpy.GetMessages(2)) # Log error if logInfo == "true": loggingFunction(logFile, "error", arcpy.GetMessages(2)) # If python error except Exception as e: # Show the message arcpy.AddError(e.args[0]) # Log error if logInfo == "true": loggingFunction(logFile, "error", e.args[0])
# First, get all the stand alone tables, feature classes and rasters owned by the current user. dataList = arcpy.ListTables( '*.' + userName + '.*') + arcpy.ListFeatureClasses( '*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*') # Next, for feature datasets owned by the current user # get all of the featureclasses and add them to the master list. for dataset in arcpy.ListDatasets('*.' + userName + '.*'): dataList += arcpy.ListFeatureClasses(feature_dataset=dataset) # Execute rebuild indexes and analyze datasets # Note: to use the "SYSTEM" option, the user must be an administrator. #workspace = "Database Connections/user1.sde" arcpy.RebuildIndexes_management(connSDE, "SYSTEM", dataList, "ALL") arcpy.AnalyzeDatasets_management(connSDE, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") ###------------------------------------------------------------- ### Rebuild indices and update statistics for second data owner gisadmin user ###------------------------------------------------------------- # set the workspace env.workspace = connGISADMIN # Get the user name for the workspace # this assumes you are using database authentication. # OS authentication connection files do not have a 'user' property.
if len(verReconcileList) > 0: # Execute the ReconcileVersions tool. # Put log in a better place in the future arcpy.ReconcileVersions_management(workspace, "ALL_VERSIONS", targetVersion, verReconcileList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "KEEP_VERSION", "c:/temp/reconcilelog.txt") # Run the compress tool. arcpy.Compress_management(workspace) # Rebuild indexes and analyze the states and states_lineages system tables arcpy.RebuildIndexes_management(workspace, "SYSTEM", "", "ALL") arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", "", "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE") ''' ********************* Data Owner(s) Section ********************* ''' # Get a list of datasets owned by the data owner user (requires second connection file) # Set the workspace # arcpy.env.workspace = 'Database Connections/dataOwner.sde' # Set a variable for the workspace
# Run the compress tool. try: LogMessage("Running compress") arcpy.Compress_management(adminConn) #if the compress is successful add a message. LogMessage('Compress was successful.') except: #If the compress failed, add a message. LogMessage('\nCompress failed: error message below.' + arcpy.GetMessages()) #Update statistics and idexes for the system tables # Note: to use the "SYSTEM" option the user must be an geodatabase or database administrator. try: LogMessage("Rebuilding indexes on the system tables") arcpy.RebuildIndexes_management(adminConn, "SYSTEM") LogMessage('Rebuilding of system table indexes successful.') except: LogMessage( 'Rebuild indexes on system tables fail: error message below.\n\r' + arcpy.GetMessages()) try: LogMessage("Updating statistics on the system tables") arcpy.AnalyzeDatasets_management(adminConn, "SYSTEM") LogMessage('Analyzing of system tables successful.') except: LogMessage('Analyze system tables failed: error message below.\n\r' + arcpy.GetMessages()) # Allow connections again.
arcpy.env.overwriteOutput = True print('gdb not accepting connections') logger.info('gdb not accepting connections') arcpy.AcceptConnections(admin, False) # Compress GDB print('Compressing Geodatabase') logger.info('Compressing Geodatabase') compress_result = arcpy.Compress_management(admin) print('Compress message: ' + compress_result.getMessage(2)) logger.info('Compress message: ' + compress_result.getMessage(2)) # Rebuild Indexes print('Rebuilding Indexes') logger.info('Rebuilding Indexes') rebuild_result = arcpy.RebuildIndexes_management(admin, 'SYSTEM') print('Rebuild result: ' + rebuild_result.getMessage(2)) logger.info('Rebuild result: ' + rebuild_result.getMessage(2)) # Update GDB statistics using Analyze print('Updating GDB statistics') logger.info('Updating GDB statistics') analyze_result = arcpy.AnalyzeDatasets_management(admin, 'SYSTEM') print('Analyze message: ' + analyze_result.getMessage(2)) logger.info('Analyze message: ' + analyze_result.getMessage(2)) # Accept connections on geodatabase arcpy.AcceptConnections(admin, True) print('gdb accepting connections') logger.info('gdb accepting connections')
def mainFunction(geodatabase,disconnectUsers): # Get parameters from ArcGIS Desktop tool by seperating by comma e.g. (var1 is 1st parameter,var2 is 2nd parameter,var3 is 3rd parameter) try: # --------------------------------------- Start of code --------------------------------------- # # If disconnecting users if (disconnectUsers == "true"): # Block any new connections to the geodatabase arcpy.AcceptConnections(geodatabase, False) arcpy.AddMessage("Disconnecting all users from " + geodatabase + "...") # Logging if (enableLogging == "true"): logger.info("Disconnecting all users from " + geodatabase + "...") arcpy.DisconnectUser(geodatabase, "ALL") # Compress the geodatabase arcpy.AddMessage("Compressing geodatabase - " + geodatabase + "...") # Logging if (enableLogging == "true"): logger.info("Compressing geodatabase - " + geodatabase + "...") arcpy.env.workspace = geodatabase arcpy.Compress_management(geodatabase) # Load in datasets to a list dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListDatasets() # Load in datasets from feature datasets to the list for dataset in arcpy.ListDatasets("", "Feature"): arcpy.env.workspace = os.path.join(geodatabase,dataset) dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets() # Reset the workspace arcpy.env.workspace = geodatabase # Get the user name for the workspace userName = arcpy.Describe(geodatabase).connectionProperties.user.lower() # Remove any datasets that are not owned by the connected user. userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1] # Execute rebuild indexes arcpy.AddMessage("Rebuilding the indexes for all tables in the database....") # Logging if (enableLogging == "true"): logger.info("Rebuilding the indexes for all tables in the database....") # Note: to use the "SYSTEM" option the workspace user must be an administrator. arcpy.RebuildIndexes_management(geodatabase, "SYSTEM", userDataList, "ALL") # Execute analyze datasets arcpy.AddMessage("Analyzing and updating the database statistics....") # Logging if (enableLogging == "true"): logger.info("Analyzing and updating the database statistics....") # Note: to use the "SYSTEM" option the workspace user must be an administrator. arcpy.AnalyzeDatasets_management(geodatabase, "SYSTEM", userDataList, "ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE") # If disconnecting users if (disconnectUsers == "true"): # Allow any new connections to the geodatabase arcpy.AddMessage("Allowing all users to connect to " + geodatabase + "...") # Logging if (enableLogging == "true"): logger.info("Allowing all users to connect to " + geodatabase + "...") arcpy.AcceptConnections(geodatabase, True) # --------------------------------------- End of code --------------------------------------- # # If called from gp tool return the arcpy parameter if __name__ == '__main__': # Return the output if there is any if output: arcpy.SetParameterAsText(1, output) # Otherwise return the result else: # Return the output if there is any if output: return output # Logging if (enableLogging == "true"): # Log end of process logger.info("Process ended.") # Remove file handler and close log file logMessage.flush() logMessage.close() logger.handlers = [] # If arcpy error except arcpy.ExecuteError: # Build and show the error message errorMessage = arcpy.GetMessages(2) arcpy.AddError(errorMessage) # Logging if (enableLogging == "true"): # Log error logger.error(errorMessage) # Log end of process logger.info("Process ended.") # Remove file handler and close log file logMessage.flush() logMessage.close() logger.handlers = [] if (sendErrorEmail == "true"): # Send email sendEmail(errorMessage) # If python error except Exception as e: errorMessage = "" # Build and show the error message for i in range(len(e.args)): if (i == 0): # Python version check if sys.version_info[0] >= 3: # Python 3.x errorMessage = str(e.args[i]).encode('utf-8').decode('utf-8') else: # Python 2.x errorMessage = unicode(e.args[i]).encode('utf-8') else: # Python version check if sys.version_info[0] >= 3: # Python 3.x errorMessage = errorMessage + " " + str(e.args[i]).encode('utf-8').decode('utf-8') else: # Python 2.x errorMessage = errorMessage + " " + unicode(e.args[i]).encode('utf-8') arcpy.AddError(errorMessage) # Logging if (enableLogging == "true"): # Log error logger.error(errorMessage) # Log end of process logger.info("Process ended.") # Remove file handler and close log file logMessage.flush() logMessage.close() logger.handlers = [] if (sendErrorEmail == "true"): # Send email sendEmail(errorMessage)
print "SDE is at State " + str(row_count - 1) while row_count <> 1: #compress the database until State 0 is achieved (i.e. one record exists in the lineage table) arcpy.Compress_management(sde) row_count = len( cur.execute("select * from sde.sde_state_lineages").fetchall()) #print cur.execute("select * from sde.sde_state_lineages").fetchall() print "SDE is at State " + str(row_count - 1) cur.close con.close print "Compress successfully completed!" print "Allow users to connect to " + str(sde) arcpy.AcceptConnections( sde, True) #allow the database to begin accepting connections again print "Rebuilding indexes on the system tables" arcpy.RebuildIndexes_management( sde, "SYSTEM") #rebuild indexes on the system tables print "Updating statistics on the system tables" arcpy.AnalyzeDatasets_management(sde, "SYSTEM") print "" print "Generating Asset IDs..." print "" except arcpy.ExecuteError: print "" print(arcpy.GetMessages(2)) print "" raw_input("Compression failure. Press ENTER to exit.") quit() #Generate Asset IDs try: #Feature Class and infrastructure prefix lists need to be insync ordinally
# Rebuild versions connections = [sde, giseditor, sewerman] versions = ["QC", "edits", "edits"] pVersion = ["sde.Default", "SDE.QC", "SDE.QC"] fullNames = ["SDE.QC", "GISEDITOR.edits", "SEWERMAN.edits"] for i, versionName in enumerate(connections): arcpy.CreateVersion_management(connections[i], pVersion[i], versions[i], "PUBLIC") log.write( str(time.asctime()) + ": " + fullNames[i] + " version created.\n") # Rebuild indexes arcpy.RebuildIndexes_management( sewerman, "NO_SYSTEM", "SDE.SEWERMAN.MANHOLES_VIEW; " "SDE.SEWERMAN.SEWERS_VIEW; " "SDE.SEWERMAN.ProjectAreas; " "SDE.SEWERMAN.REPAVING", "ALL") log.write(str(time.asctime()) + ": Indexes rebuilt.\n") # Analyze datasets arcpy.AnalyzeDatasets_management( sewerman, "NO_SYSTEM", "SDE.SEWERMAN.MANHOLES_VIEW; " "SDE.SEWERMAN.SEWERS_VIEW; " "SDE.SEWERMAN.ProjectAreas; " "SDE.SEWERMAN.REPAVING", "ANALYZE_BASE", "NO_ANALYZE_DELTA", "ANALYZE_ARCHIVE") log.write(str(time.asctime()) + ": Analyze complete.\n") # Send "success" email. successSubj = "Script Completed"
print 'WARNING \n fileLog path may not exist.' #------------------------------------------------------------------------------- # Process: Rebuild Indexes """ This tool is used in databases and enterprise, workgroup, and desktop geodatabases to rebuild existing attribute or spatial indexes. In enterprise, workgroup, and desktop geodatabases, indexes can also be rebuilt on states and state_lineage geodatabase system tables and the delta tables of versioned datasets. Out-of-date indexes can lead to poor query performance. """ try: print 'Rebuilding Indexes at: ' + sdeConnectionFile logging.info('Rebuilding Indexes') arcpy.RebuildIndexes_management(sdeConnectionFile, "SYSTEM", "", "ALL") except Exception as e: print 'ERROR!!!' logging.info('ERROR!!!') print str(e) logging.info(str(e)) success = False #------------------------------------------------------------------------------- # Print final message based on if successful or not if success == True: print '\nSUCCESS \n Done running Rebuild_Indexes.py' logging.info('SUCCESS \n Done running Rebuild_Indexes.py')