Skip to content

Instantly share code, notes, and snippets.

@dersteppenwolf
Created August 23, 2012 04:43
Show Gist options
  • Save dersteppenwolf/3432495 to your computer and use it in GitHub Desktop.
Save dersteppenwolf/3432495 to your computer and use it in GitHub Desktop.
Comprimir SDE y Analizar Schema (Arcgis 10, arcpy)
#-*- coding: UTF-8 -*-
#Script para ejecutar el compress y analyze de la base de datos
#Basado en el Script original para arcgis 9.3.1 por Mike Long - [email protected]
import string, os, arcpy, time
import traceback,sys
from arcpy import env
# Set the date.
Date = time.strftime("%m-%d-%Y", time.localtime())
# Set the time.
Time = time.strftime("%I:%M:%S %p", time.localtime())
print "Process started at " + str(Date) + " " + str(Time) + "." + "\n"
sdeConnFilePath = "C:\\temp\\my_sde_conn.sde"
analyzeworkspace = "C:\\temp\\my_schema.sde"
logFilePath = 'c:\\temp\\GIS-' + Date + '.txt'
# Set up the log file.
LogFile = file(logFilePath, 'w') #Creates a log file with todays date.
output = open(logFilePath, 'w') #Path to log file.
output.write(str("Process started at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.
try:
# Compress the database
print "Begining Compress..." + "\n"
output.write("Begining Compress..." + "\n")
#gp.toolbox = "management"
# For this script to work it will need the full path to the .sde connection file.
arcpy.Compress_management(sdeConnFilePath)
print arcpy.GetMessages() + "\n"
output.write(arcpy.GetMessages() + "\n")
except Exception as e:
print arcpy.GetMessages()
output.write("Error Compressing the GIS Database")
output.write(arcpy.GetMessages())
output.write(e)
output.write(e.args[0])
output.write(arcpy.GetMessages())
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
output.write( tbinfo )
output.write( sys.exc_type )
output.write( sys.exc_value )
try:
output.write("Begining analyze..." + "\n")
env.workspace = analyzeworkspace
# Loop through and analyze all the Tables.
# The if-else statements set the script to skip over Multi-Versioned Views.
#gp.Workspace = analyzeworkspace
output.write("\nAnalyzing tables\n")
for TB in arcpy.ListTables("*", "all"):
output.write("Analyzing table:"+TB)
if '_MVVIEW' in TB:
output.write("Skipping Multi-Versioned View")
elif '_MVView' in TB:
output.write("Skipping Multi-Versioned View")
elif 'SDE.' in TB:
output.write("\nSkipping table SDE\n")
else:
arcpy.Analyze_management(TB, "BUSINESS;FEATURE;ADDS;DELETES")
print arcpy.GetMessages() + "\n"
output.write(arcpy.GetMessages())
# Loop through and analyze all Feature datasets
output.write("\nAnalyzing featureClasses\n")
for FC in arcpy.ListFeatureClasses("*", "all"):
output.write("\nAnalyzing featureClass:"+FC)
if 'VV_' in FC:
print "Skipping View"
output.write("\nSkipping View\n")
continue
arcpy.Analyze_management(FC, "BUSINESS;FEATURE;ADDS;DELETES")
print arcpy.GetMessages() + "\n"
output.write(arcpy.GetMessages() + "\n")
# Loop through and analyze all the Feature classes
#gp.Workspace = analyzeworkspace
output.write("\nAnalyzing datasets\n")
for FD in arcpy.ListDatasets("*", "all"):
output.write("\nAnalyzing dataset:"+FD)
arcpy.Analyze_management(FD, "BUSINESS;FEATURE;ADDS;DELETES")
print arcpy.GetMessages() + "\n"
output.write(arcpy.GetMessages())
except Exception as e:
output.write("\nError...\n")
print arcpy.GetMessages()
output.write("Error Analyzing the GIS Database\n")
output.write(arcpy.GetMessages())
output.write(str(e))
output.write(e.args[0])
output.write(arcpy.GetMessages())
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
output.write( tbinfo )
output.write( str(sys.exc_type) )
output.write( str(sys.exc_value ))
# Sets the Date & Time since the script started.
Date = time.strftime("%m-%d-%Y", time.localtime())# Set the date.
Time = time.strftime("%I:%M:%S %p", time.localtime()) # Set the time.
output.write(str("Process completed at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.
output.close() # Closes the log file.
print "Process completed at " + str(Date) + " " + str(Time) + "."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment