ListVersions (arcpy.da)

Zusammenfassung

Lists the versions in the workspace.

Diskussion

You can specify the path to an ArcSDE connection file as an argument to the function or you can set the workspace environment to the ArcSDE Connection file and call the ListVersions function without any arguments.

HinweisHinweis:

The arcpy.da.ListVersions function should not to be confused with the arcpy.ListVersions function which is used to return a list of version names the connected user has permission to use.

Syntax

ListVersions (sde_workspace)
ParameterErläuterungDatentyp
sde_workspace

An ArcSDE geodatabase workspace.

String
Rückgabewert
DatentypErläuterung
Version

The Python list returned from the function containing Version objects.

Codebeispiel

ListVersions example 1

Identify all versions modified within the last week.

import arcpy
import datetime

# Use datetime to establish current date/time
#
now = datetime.datetime.now()

sdeConnection = "Database Connections/toolboxDEFAULTVersion.sde"

# Compare lastModified property of each version to current date, and 
#  print version name if the version was modified in the last 7 days.
#
for version in arcpy.da.ListVersions(sdeConnection):
    if (now - version.lastModified).days < 7:
        print(version.name)
ListVersions example 2

Delete any versions belonging to a particular user and have no children.

import arcpy

sdeConnection = "Database Connections/toolboxDEFAULTVersion.sde"

for version in arcpy.da.ListVersions(sdeConnection):
    # Delete any versions owned by "RJones" that don't have any children
    #
    if version.name.split(".")[0] == "RJones" and not version.children:
        print("Deleting version {0}".format(version.name))
        arcpy.DeleteVersion_management(sdeConnection, version.name)

Verwandte Themen

9/11/2013