Resumen
Enumera las versiones en el espacio de trabajo.
Debate
Nota:
La función arcpy.da.ListVersions no se debería confundir con la función arcpy.ListVersions, que se utiliza para devolver una lista de nombres de versiones que el usuario conectado tiene permiso para usar.
Muestra de código
Identifique todas las versiones modificadas en la última semana.
import arcpy
import datetime
# Use datetime to establish current date/time
#
now = datetime.datetime.now()
sdeConnection = "C:/MyProject/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)
Elimine todas las versiones que pertenezcan a un usuario concreto y que no tengan versiones secundarias.
import arcpy
sdeConnection = "C:/MyProject/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)
Concilie y publique versiones con una descripción específica. Este ejemplo utiliza un servicio de entidades que tiene la funcionalidad de administración de versiones habilitada.
# Import system modules
import arcpy
# Sign into ArcGIS Enterprise
arcpy.SignInToPortal("https://myserver.mydomain.com/portal", 'portaladmin',
'my.password')
# Create a variable for the feature service URL
myFS = "https://myserver.mydomain.com/server/rest/services/BranchVersioningData/FeatureServer"
# Use the ListVersions function to get a list of versions
versions = arcpy.da.ListVersions(myFS)
# Create a list of version to reconcile
listToRec = []
# For each version in the list, append only those that have the "READY TO POST"
# description
for version in versions:
if "READY FOR POST" in version.description.upper():
listToRec.append(version.name)
# Reconcile and post the versions
arcpy.ReconcileVersions_management(myFS,
'ALL_VERSIONS',
'sde.DEFAULT',
listToRec,
'NO_LOCK_ACQUIRED',
'ABORT_CONFLICTS',
'BY_OBJECT',
'FAVOR_EDIT_VERSION',
'POST',
'KEEP_VERSION')