Error Handling & Writing to Text File

Discussion created by MLF on Jan 17, 2014
Latest reply on Jan 17, 2014 by MLF
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!
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"
    arcpy.SynchronizeChanges_management(WRITESDE_MNP, "MNP.MNP_Roads_Read", READONLYSDE_MNP, "FROM_GEODATABASE1_TO_2", "", "", "")
    f.write("Synced MNP.MNP_Roads_Read Replica\n")
    f.write("Problem syncing MNP.MNP_Roads_Read Replica\n")