Erstellen eines Skripts für die Aktualisierung einer ArcSDE-Geodatabase in Informix

Sie können die in diesem Thema bereitgestellten Python-Skripts ändern und verwenden, um eine Verbindung zu einer ArcSDE-Geodatabase herzustellen und diese zu aktualisieren.

Das erste Skript verwendet eine vorhandene ArcSDE-Verbindungsdatei, um eine Verbindung mit der Geodatabase herzustellen und diese zu aktualisieren.

Das zweite Skript zeigt an, wie Sie Verbindungsinformationen in demselben Skript, das zur Aktualisierung der Geodatabase verwendet wird, bereitstellen können. Dies ist besonders hilfreich, wenn Sie keinen Zugriff auf ArcGIS Desktop haben; Sie können das Python-Skript von einem Computer ausführen, auf dem ArcGIS Engine oder ArcGIS Server Enterprise (Standard oder Advanced) installiert ist, Verbindungsinformationen angeben und die Geodatabase aktualisieren.

Bei der Verbindung zur Geodatabase handelt es sich stets um eine direkte Verbindung, egal ob Sie eine vorhandene ArcSDE-Verbindungsdatei oder Parameter im Skript verwenden. Sie müssen daher einen IBM Informix-Client auf dem Computer installieren und konfigurieren, auf dem Sie das Skript ausführen werden.

Vor der Aktualisierung sollten Sie unbedingt die folgenden Themen gelesen und die darin enthaltenen Schritte ausgeführt haben: Vorbereiten der Aktualisierung einer Geodatabase in Informix.

Schritte:
  1. Copy one of these example scripts to the Python window in ArcGIS Desktop, or to any Python IDE such as PythonWin or WING. Alter any variable values to match the information at your site.
    • Wenn Sie über eine vorhandene ArcSDE-Verbindungsdatei verfügen, die eine direkte Verbindung verwendet und eine Verbindung als ArcSDE-Administrator herstellt, kopieren und ändern Sie eines der folgenden Skripte je nach Betriebssystem:
      # Name: upgradesdegdb_example.py
      # Description: Connect from a Windows computer 
      # with an existing ArcSDE connection file 
      # and upgrade an ArcSDE for Informix geodatabase
      # Author: ESRI
      
      # Import arcpy module
      import arcpy
       
      # Local variables:
      Output_Workspace = "C:\\ArcGIS\connection_files\<Connection file>"
      Default_gdb = "C:\\ArcGIS\connection_files\<Connection file>"
      
      # Process: Upgrade Geodatabase
      arcpy.UpgradeGDB_management(<Connection file>, "PREREQUISITE", "UPGRADE")
      # Name: upgradesdegdb_example.py
      # Description: Connect from a Linux or UNIX computer 
      # with an existing ArcSDE connection file 
      # and upgrade an ArcSDE for Informix geodatabase
      # Author: ESRI
      
      # Import arcpy module
      import arcpy
       
      # Local variables:
      Output_Workspace = "<user>/connections/<Connection_file>"
      Default_gdb = "<user>/connections/<Connection_file>"
      
      # Process: Upgrade Geodatabase
      arcpy.UpgradeGDB_management(<Connection_file>, "PREREQUISITE_CHECK", "UPGRADE")
    • Wenn keine ArcSDE-Verbindungsdatei auf dem Computer vorhanden ist, auf dem Sie das Skript für die Aktualisierung erstellen, können Sie das folgende Skript kopieren und ändern:
      """
      Name: upgrade_gdb.py
      Description: Provide connection information to an Enterprise geodatabase 
      and upgrade the geodatabase
      Type upgrade_gdb.py -h or upgrade_gdb.py --help for usage
      """
      
      # Import system modules
      import arcpy, os, optparse, sys
      
      
      # Define usage and version
      parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0; valid for 10.0 and 10.1 release")
      
      #Define help and options
      parser.add_option ("-s", dest="Server", type="string", default="", help="RDBMS server name")
      parser.add_option ("-i", dest="Service", type="string", default="", help="Use direct connection syntax")
      parser.add_option ("--auth", dest="account_authentication", type ="choice", choices=['DATABASE_AUTH', 'OPERATING_SYSTEM_AUTH'], default='DATABASE_AUTH', help="Authentication type options (case-sensitive):  DATABASE_AUTH, OPERATING_SYSTEM_AUTH.  Default=DATABASE_AUTH")
      parser.add_option ("-u", dest="User", type="string", default="", help="Geodatabase administrator user name")
      parser.add_option ("-p", dest="Password", type="string", default="", help="Geodatabase administrator password")
      parser.add_option ("-v", dest="Version", type="string", help="ArcSDE version name")
      parser.add_option ("--upgrade", dest="Upgrade", type="choice", choices=['TRUE', 'FALSE'], default="FALSE", help="Upgrade Options (case-sensitive):  TRUE=Perform Pre-requisite check and upgrade geodatabase, FALSE=Perform Pre-requisite check only.  Default=FALSE")                   
      parser.add_option ("-d", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
      
      
      # Check if value entered for option
      try:
      	(options, args) = parser.parse_args()
      
      	
      #Check if no system arguments (options) entered
      	if len(sys.argv) == 1:
      		print "%s: error: %s\n" % (sys.argv[0], "No command options given")
      		parser.print_help()
      		sys.exit(3)
      	
      
      	#Usage parameters for spatial database connection to upgrade
      	server = options.Server
      	service = options.Service	
      	account_authentication = options.account_authentication.upper()
      	username = options.User.lower() 
      	password = options.Password	
      	version = options.Version.upper()
      	do_upgrade = options.Upgrade
      	database = options.Database.lower()
      	
      	
      	# Get the current product license
      	product_license=arcpy.ProductInfo()
      	
      	
      	# Checks required license level to upgrade
      	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
      		print "\n" + product_license + " license found!" + "  Enterprise geodatabase upgrade requires an ArcEditor, ArcInfo, ArcGIS Engine Geodatabase Update, or ArcGIS Server license."
      		sys.exit("Re-authorize ArcGIS before upgrading.")
      	else:
      		print "\n" + product_license + " license available!  Continuing to upgrade..."
      		arcpy.AddMessage("+++++++++")
      	
      	
      	# Check if direct connection
      	if service.find(":") <> -1:  #This is direct connect
      		ServiceConnFileName = service.replace(":", "")
      		ServiceConnFileName = ServiceConnFileName.replace(";", "")
      		ServiceConnFileName = ServiceConnFileName.replace("=", "")
      		ServiceConnFileName = ServiceConnFileName.replace("/", "")
      		ServiceConnFileName = ServiceConnFileName.replace("\\", "")
      	else:
      		arcpy.AddMessage("\n+++++++++")
      		arcpy.AddMessage("Exiting!!")
      		arcpy.AddMessage("+++++++++")
      		sys.exit("\nSyntax for a direct connection in the Service parameter is required for geodatabase upgrade.")
      	
      	
      	# Local variables
      	Conn_File_NameT = server + "_" + ServiceConnFileName + "_" + database + "_" + username    
      	
      	if os.environ.get("TEMP") == None:
      		temp = "c:\\temp"	
      	else:
      		temp = os.environ.get("TEMP")
      	
      	if os.environ.get("TMP") == None:
      		temp = "/usr/tmp"		
      	else:
      		temp = os.environ.get("TMP")  
      	
      	Connection_File_Name = temp + os.sep + Conn_File_NameT + ".sde"
      	
      	
      	# Check for the .sde file and delete it if present
      	arcpy.env.overwriteOutput=True
      	
      	
      	# Variables defined within the script; other variable options commented out at the end of the line
      	saveUserInfo = "SAVE_USERNAME" #DO_NOT_SAVE_USERNAME
      	saveVersionInfo = "SAVE_VERSION" #DO_NOT_SAVE_VERSION
      	
      	
      	print "\nCreating ArcSDE Connection File...\n"
      	# Process: Create ArcSDE Connection File...
      	# Usage: out_folder_path, out_name, server, service, database, account_authentication, username, password, save_username_password, version,   save_version_info
      	arcpy.CreateArcSDEConnectionFile_management(temp, Conn_File_NameT, server, service, database, account_authentication, username, password, saveUserInfo, version, saveVersionInfo)
      	for i in range(arcpy.GetMessageCount()):
      		if "000565" in arcpy.GetMessage(i):   #Check if database connection was successful
      			arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("\n+++++++++")
      			arcpy.AddMessage("Exiting!!")
      			arcpy.AddMessage("+++++++++\n")
      			sys.exit(3)            
      		else:
      			arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("+++++++++\n")
      	
      	
      	# Process: Upgrade geodatabase...
      	try:
      		if do_upgrade.lower() == "true":
      			print "Upgrading Geodatabase...\n"
      			arcpy.UpgradeGDB_management(Connection_File_Name, "PREREQUISITE_CHECK", "UPGRADE")
      			for i in range(arcpy.GetMessageCount()):
      				arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("+++++++++\n")
      	
      		else:
      			print "Running Pre-Requisite Check...\n"
      			arcpy.UpgradeGDB_management(Connection_File_Name, "PREREQUISITE_CHECK", "NO_UPGRADE")
      			for i in range(arcpy.GetMessageCount()):
      				arcpy.AddReturnMessage(i)
      			arcpy.AddMessage("+++++++++\n")
      	
      	except:
      		for i in range(arcpy.GetMessageCount()):
      			arcpy.AddReturnMessage(i)
      			
      #Check if no value entered for option	
      except SystemExit as e:
      	if e.code == 2:
      		parser.usage = ""
      		print "\n"
      		parser.print_help()   
      		parser.exit(2)
  2. Führen Sie das Skript aus, das Sie kopiert und geändert haben, um die Voraussetzungsprüfung auszuführen und die Geodatabase zu aktualisieren.

    Weitere Informationen zur Verwendung von Python finden Sie unter Verfassen von Python-Skripten.

Verwandte Themen


7/10/2012