ListVersions

描述

列出工作空间中的数据版本。

讨论

可以指定连接文件的路径或者要素服务 URL 作为函数的参数,或者将工作空间环境设置为连接文件或要素服务 URL,并调用不带任何参数的 ListVersions 函数。

注:

不能将 arcpy.da.ListVersions 函数与 arcpy.ListVersions 函数相混淆,后者用于返回一个已连接用户有权使用的版本名称列表。

语法

ListVersions (sde_workspace)
参数说明数据类型
sde_workspace

启用了版本管理功能的企业级地理数据库工作空间或要素服务。

String
返回值
数据类型说明
Version

Version 对象的列表。

代码示例

ListVersions 示例 1

识别上周修改的所有数据库版本。

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)
ListVersions 示例 2

请删除所有属于特定用户不具有任何子版本的数据库版本。

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)
ListVersions 示例 3

协调并提交具有特定说明的版本。本示例将使用启用了版本管理功能的要素服务。

# 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')

相关主题