Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Error Handling & Writing to Text File

$
0
0
Hello! I have a script which runs nightly to synchronize multiple replicas. The script creates a txt log. If a synch fails, it writes "failed" to the text file, and "success" otherwise.

Recently, one of the replicas failed to synch. It did not impede the rest of the synchs. The log text file was created, but no content was written to it. I'm not sure why--any ideas?

Also, I removed a bunch of replicas from this script and modified the directory names, in the interest of simplicity.

Thank you!
Code:


import arcpy,sys,time

timestr = time.strftime("%Y%b%d-%I%M%S%p")
LogFilePath = '\\\abcsrv\\spatialStaff\\Replicas\\ReplicaSynchronizationLogs'
final = LogFilePath + "\\" + timestr + "-ReplicaSync.txt"
f = open(final,'w')
READONLYSDE_MNP = "\\\\abcsrv\\spatialStaff\\SDE_Connection_Files\\READONLYSDE_MNP.sde"
WRITESDE_MNP = "\\\\abcsrv\\spatialStaff\\SDE_Connection_Files\\WRITESDE_MNP.sde"
try:
    arcpy.SynchronizeChanges_management(WRITESDE_MNP, "MNP.MNP_Roads_Read", READONLYSDE_MNP, "FROM_GEODATABASE1_TO_2", "", "", "")
    f.write("Synced MNP.MNP_Roads_Read Replica\n")
except:
    f.write("Problem syncing MNP.MNP_Roads_Read Replica\n")
f.close()


Viewing all articles
Browse latest Browse all 2485

Trending Articles