Пример #1
0
def createver(key, workspace):
    #loop keys for versions
    #get version name and attemp to create new version
    for k in key:
        for key in k:
            if 'version-name' in key:

                #Execute CreateVersion
                #attemp to create new version
                try:
                    arcpy.CreateVersion_management(workspace,
                                                   k['parent-version'],
                                                   k['version-name'],
                                                   k['access-permission'])
                    print ' Create version: %s' % k['version-name']
                except:
                    log.error("Create version " + k['version-name'] +
                              " Failed.")

                #Alter Version
                #attemp to alter version
                try:
                    arcpy.AlterVersion_management(
                        workspace, k['version-name'], k['version-name'],
                        'version for: ' + k['version-name'],
                        k['access-permission'])
                except:
                    logger.error("Alter version " + k['version-name'] +
                                 " Failed.")
Пример #2
0
def CreateSDE_Version():
	'''This is to make sure that the version exists before the script runs'''
	print("Checking SDE connections.\n")
	sdeTempPath = tempfile.mkdtemp()
	arcpy.CreateDatabaseConnection_management(sdeTempPath, "Editor.sde", "SQL_SERVER", SERVERNAME, "OPERATING_SYSTEM_AUTH")
	sdeVersionNameFULL = ""
	sdeVersionLIST = []
	for version in arcpy.da.ListVersions(sdeTempPath + os.sep + "Editor.sde"):
		sdeVersionNameFULL = version.name.split(".")[0]        
		sdeVersionLIST.append(sdeVersionNameFULL)
		if sdeVersionNameFULL == '"MCKINNEY\\JCARMONA"':
			if version.description == "":
				arcpy.AlterVersion_management(sdeTempPath + os.sep + "Editor.sde", '"MCKINNEY\JCARMONA".CARMONA', description = "[email protected] | ext 7422")
		#print(sdeVersionLIST)
	if '"MCKINNEY\\JCARMONA"' not in sdeVersionLIST:
		print("\tCARMONA version not found, creating now.")
		arcpy.CreateVersion_management(sdeTempPath + os.sep + "Editor.sde", "sde.DEFAULT" ,"CARMONA", "PUBLIC")
		arcpy.AlterVersion_management(sdeTempPath + os.sep + "Editor.sde", '"MCKINNEY\JCARMONA".CARMONA', description = "[email protected] | ext 7422")
		print("Version created.")
	shutil.rmtree(sdeTempPath)
Пример #3
0
def createVersion(sde, defaultVersion, versionName):
    # create a version in the database
    retcode = False
    loc = versionName.find(".")
    if loc > -1:
        versionName = versionName.split(".")[1]
    addMessageLocal("Creating Version: " + versionName)
    try:
        retcode = arcpy.CreateVersion_management(sde, defaultVersion,
                                                 versionName, "PRIVATE")
        if debug == True:
            addMessageLocal("create version " + str(retcode))
    except:
        if debug == True:
            addMessageLocal("create version exception: " + str(retcode))
        retcode = False  # have to assume this means it exists already
        try:  # but try to change it to check
            retcode = arcpy.AlterVersion_management(
                sde, versionName, "", "Version for Data loading", "PRIVATE")
            if debug == True:
                addMessageLocal("alter version " + str(retcode))
            #addMessageLocal "Alter version succeeded"
        except:
            addMessageLocal(
                "Create version failed - please try to manually delete any existing version in ArcCatalog"
            )
            addMessageLocal("Error: " + str(sys.exc_value))
            retcode = False  # if we can't change it the version probably doesn't exist
            if debug == True:
                addMessageLocal("except: alter version (doesn't exist) " +
                                str(retcode))
            exit(-1)

    if retcode != False:  # this means that the create version call returned a value
        retcode = True
    if debug == True:
        addMessageLocal("final retcode " + str(retcode))
    return retcode