ListReplicas

摘要

ListReplicas 函数可列出工作空间中的复本。

说明

可以指定作为函数参数的连接文件的路径,或为连接文件设置工作空间环境并调用不带任何参数的 ListReplicas 函数。

语法

ListReplicas (workspace, {all_replicas})
参数说明数据类型
workspace

The geodatabase workspace.

String
all_replicas

Specifies whether all replica types in the geodatabase will be returned.

  • True—All replica types will be returned. This may include Replica or SyncReplica objects.
  • False—Only Replica objects will be returned. These include replicas created from geodatabase replication workflows as well as replicas created from feature services running on traditional versioned data. This is the default.

(默认值为 False)

Boolean
返回值
数据类型说明
Replica

从包含 Replica 对象的函数返回的列表。

如果 all_replicas 参数设置为 True,则也可能会返回 SyncReplica 对象。

代码示例

ListReplicas 示例 1

为作为发送方的工作空间中的各个复本调用 ExportDataChangeMessage 函数。

import arcpy
import os

sdeConnection = "C:/Data/toolboxDEFAULTVersion.sde"
outLocation = "C:/data"

for replica in arcpy.da.ListReplicas(sdeConnection):
    # If the replica is a sender, call ExportDataChangeMessage
    if replica.isSender:
        changesFile = os.path.join(outputLocation,
                                   f"changes_{replica.name}.gdb")
        arcpy.management.ExportDataChangeMessage(sdeConnection,
                                                 changes,
                                                 replica.name)
ListReplicas 示例 2

打印所有存在冲突的复本。

import arcpy

sdeConnection = "C:/Data/toolboxDEFAULTVersion.sde"

# Print the name of the replicas that are in conflict
for replica in arcpy.da.ListReplicas(sdeConnection):
    if replica.hasConflicts:
        print(replica.name)
ListReplicas 示例 3

打印 SyncReplica 对象的属性

import arcpy

# Use the ListReplicas function to return all replicas in the geodatabase
replicas = arcpy.da.ListReplicas("C:\\Projects\\MyProject\\myGDB.sde", True)

for r in replicas:
    # Check if the class is a SyncReplica
    if isinstance(r, arcpy.da.SyncReplica):
        # Print the properties of a SyncReplica object
        print(f"Properties of replica named: {r.name}")
        print(f"Datasets: {r.datasets}")
        print(f"Owner: {r.owner}")
        print(f"Replica ID: {r.replicaID}")
        print(f"Service name: {r.serviceName}")
        print(f"Version: {r.version}")
        print(f"Direction: {r.direction}")
        print(f"Sync model: {r.syncModel}")
        print(f"Last sync date: {r.lastSyncDate}")
        print(f"LayerServerGens: {r.layerServerGens}")
        print(f"LayerServerSibGens: {r.layerServerSibGens}")
        print(f"ReplicaServerGen: {r.replicaServerGen}")
        print(f"ReplicaServerSibGen: {r.replicaServerSibGen")
        print(f"Target type: {r.targetType}")
ListReplicas 示例 4

打印每个 ReplicaSyncReplica 对象的 creationDatereplicaDategeometry 属性。 ReplicaSyncReplica 对象可具有 creationDate 属性值,replicaDate 属性值或两者兼有。 creationDatereplicaDate 属性用于描述复本的创建时间,但 creationDate 属性使用 UTC 时间,而 replicaDate 属性使用服务器计算机的时区。 geometry 属性是复本的空间过滤器几何。

import arcpy

# Use the ListReplicas function to return all Replicas and SyncReplicas in the geodatabase
replicas = arcpy.da.ListReplicas("C:\\gdb\\mygeodatabase.sde", True)

for r in replicas:
    # Print Replica or SyncReplica object properties
    if hasattr(r, 'creationDate'):
        print(str(r.creationDate))  
    if hasattr(r, 'replicaDate'):
        print(str(r.replicaDate))
    if hasattr(r, 'geometry') and (r.geometry is not None):
        print(str(r.geometry.JSON))

相关主题


在本主题中