AnsweredAssumed Answered

Reconcile & Post Question

Question asked by NEOMAPPER on Mar 13, 2018
Latest reply on May 31, 2018 by andrescastillo08

I created a version called GIS.GIS Data so that operators out in the field could GPS data and I could review it and post the edits to my own version before reaching the Default. My only concern is that our current reconcile and post scripts is grabbing data from each of the child versions under the Default each night. Is there a command in python that would exclude any child versions created underneath another child version from being reconciled and posted to the default? I am very new to the workflow and I would really appreciate some guidance. Thanks

 

 

import arcpy, time, smtplib, os

deleteVersions = False
arcpy.env.overwriteOutput = True
reconcileLog = r'C:\temp\Daily_Reconcile_Log\Reconcile_Log.txt'

# set the workspace
arcpy.env.workspace = 'C:\Users\jnmiller\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\SDE.sde'

# Set a variable for the workspace
adminConn = arcpy.env.workspace

# Block new connections to the database.
#print("The database is no longer accepting connections")
#arcpy.AcceptConnections(adminConn, False)

# Wait 15 minutes
#time.sleep(900)

# Disconnect all users from the database.
print("Disconnecting all users")
arcpy.DisconnectUser(adminConn, "ALL")

# Get a list of versions to pass into the ReconcileVersions tool.
print("Getting list of all versions")
versionList = arcpy.ListVersions(adminConn)

for version in versionList:
    if 'default' in version.lower():
        if 'dbo' in version.lower():
            defaultVersion = 'dbo.DEFAULT'
        elif 'sde' in version.lower():
            defaultVersion = 'sde.DEFAULT'


# Execute the ReconcileVersions tool.
print("Reconciling/posting/deleting all versions")
if deleteVersions:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "DELETE_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
else:
    try:
        arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", defaultVersion, versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "KEEP_VERSION", reconcileLog)
    except:
        reconcileMessage = "Reconcile failed:  " + arcpy.GetMessages() + ".  Check reconcilelog.txt file in the " + str(reconcileLog)
        arcpy.AddWarning(reconcileMessage)
        pass
print("Completed Reconcile & Post")

# Run the compress tool.
print("Running compress")

arcpy.Compress_management(adminConn)
print("Compress Completed")

# Allow the database to begin accepting connections again
#print("Allow users to connect to the database again")
#arcpy.AcceptConnections(adminConn, True)

print("Starting Rebuild Indexes")
# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()

# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
    arcpy.env.workspace = os.path.join(adminConn,dataset)
    dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()

# Get the user name for the workspace
userName = arcpy.Describe(adminConn).connectionProperties.user.lower()

# remove any datasets that are not owned by the connected user.
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]

# Execute rebuild indexes
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.RebuildIndexes_management(adminConn, "SYSTEM", userDataList, "ALL")
print('Rebuild Complete')

# Update statistics on the system tables
# print("Updating statistics on the system tables")
# Execute analyze datasets
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.AnalyzeDatasets_management(adminConn, "SYSTEM", userDataList, "ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE")
print("Analyze Complete")

print("Finished.")

Outcomes