Script & Tool之Compress & Analyze

来源:互联网 发布:linux安装软件deb 编辑:程序博客网 时间:2024/06/05 09:02
  Arcpy(arcgis10+python2.6) 改编# This script is designed to compress an SDE Geodatabase and then# loop through and analyze the statistics of each feature dataset, view,feature class and table.# It is designed to log the entire process to a text file and# if there are any errors during the process the script will email a specified address.# Created by tony.gu - tony.gu@gisinfo.com# Last Modified on 11/08/11import arcpy, time, smtplibfrom arcpy import envcompress_workspace=arcpy.GetParameterAsText(0)analyze_workspace=arcpy.GetParameterAsText(1)env.workspace=compress_workspaceDate = time.strftime("%m-%d-%Y", time.localtime())# Set the date.Time = time.strftime("%I:%M:%S %p", time.localtime())# Set the time.print "Process started at " + str(Date) + " " + str(Time) + "." + "\n"# Set up the log file.LogFile = file('C:\\ArcScripts\\GIS-' + Date + '.txt', 'w') #Creates a log file with todays date.output = open('C:\\ArcScripts\\GIS-' + Date + '.txt', 'w') #Path to log file.output.write(str("GISINFO"+"\n"+"Process started at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.try:    # Compress the database    print "Begining Compress..." + "\n"    arcpy.Compress_management(compress_workspace)    print arcpy.GetMessages() + "\n"    output.write(arcpy.GetMessages()+ "\n")except:    #Sets up the email parameters    From = "Geoprocessor"    To = ["tony.gu@gisinfo.com"]    Date = time.ctime(time.time())    Subject = "Error Compressing the GIS Database"    Text = arcpy.GetMessages()    #Format mail message    mMessage = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' %                (From, To, Date, Subject, Text))    print 'Connecting to Server'    s = smtplib.SMTP('smtp.ym.163.com') # This needs to be set to your email server.    #Send Email    rCode = s.sendmail(From, To, mMessage)    s.quit()    if rCode:        print 'Error Sending Message'    else:        print 'Message sent sucessfully'env.workspace=analyze_workspacetry:    # Loop through and analyze all Feature datasets    FCList = arcpy.ListFeatureClasses ("*", "all")    for FC in FCList:        arcpy.Analyze_management(FC, "BUSINESS;FEATURE;ADDS;DELETES")        print arcpy.GetMessages() + "\n"        output.write(arcpy.GetMessages()+ "\n")           DSList = arcpy.ListDatasets ("*", "all")    for DS in DSList:        arcpy.Analyze_management(DS, "BUSINESS;FEATURE;ADDS;DELETES")        print arcpy.GetMessages() + "\n"        output.write(arcpy.GetMessages())           # Loop through and analyze all the Tables.    # The if-else statements set the script to skip over Multi-Versioned Views.       TBList = arcpy.ListTables ("*", "all")    for TB in TBList:        if '_MVVIEW' in TB:            print "Skipping Multi-Versioned View"        elif '_MVView' in TB:            print "Skipping Multi-Versioned View"        else:            arcpy.Analyze_management(TB, "BUSINESS;FEATURE;ADDS;DELETES")            print arcpy.GetMessages() + "\n"            output.write(arcpy.GetMessages())except:    print arcpy.GetMessages()    output.write(arcpy.GetMessages())    #Sets up the email parameters    From = "Geoprocessor"    To = ["tony.gu@gisinfo.com"]    Date = time.ctime(time.time())    Subject = "Error Analyzing the GIS Database"    Text = arcpy.GetMessages()    #Format mail message    mMessage = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' %                (From, To, Date, Subject, Text))    print 'Connecting to Server'    s = smtplib.SMTP('smtp.ym.163.com')    #Send Email    rCode = s.sendmail(From, To, mMessage)    s.quit()    if rCode:        print 'Error Sending Message'    else:        print 'Message sent sucessfully'# 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) + "."