0

I'm automating some sde geodatabase management. In the ReconcileVersions_management function there is an option create a log file of the result ("reconcileLog"). If the script runs five nights a week it will create 260 text files. In the script I already have a text file that I append a message to at each step of the script and each time the script runs. I would like to append the "reconcileLog" to the "log" file that I maintain. Not sure how to do this?

# Create a text file for logging
log = open("C:\\Compress Script\\CompressLog.txt", "a")
log.write("***********************************************************\n")



# Later in the script
reconcileLog = r"C:\Compress Script\ReconcileLog" + str(datetime.date.today()) + ".txt"
arcpy.ReconcileVersions_management(defaultWorkspace,
                                   "ALL_VERSIONS",
                                   "sde.DEFAULT",
                                   versionList,
                                   "LOCK_ACQUIRED",
                                   "ABORT_CONFLICTS",
                                   "BY_OBJECT",
                                   "FAVOR_EDIT_VERSION",
                                   "POST",
                                   "KEEP_VERSION",
                                   reconcileLog)
log.write(str(time.asctime()) + ": Edit versions reconciled and posted to DEFAULT.\n")
1
  • Just open the log txt in append mode and open the reconcileLog in read mode, loop through it and write each line to the log.txt (write additional comments if needed).
    – artwork21
    Commented Jan 5, 2016 at 14:40

1 Answer 1

1

As mentioned in the comments, open the reconcile log file, iterate through each line, and write it to your log text file.

# Create a text file for logging
log = open("C:\\Compress Script\\CompressLog.txt", "a")
log.write("***********************************************************\n")

# Later in the script
reconcileLog = r"C:\Compress Script\ReconcileLog" + str(datetime.date.today()) + ".txt"
arcpy.ReconcileVersions_management(defaultWorkspace,
                                   "ALL_VERSIONS",
                                   "sde.DEFAULT",
                                   versionList,
                                   "LOCK_ACQUIRED",
                                   "ABORT_CONFLICTS",
                                   "BY_OBJECT",
                                   "FAVOR_EDIT_VERSION",
                                   "POST",
                                   "KEEP_VERSION",
                                   reconcileLog)

#open rec file
with open (reconcileLog, "r") as recFl:
    #iterate lines in rec file
    for line in recFld:
        #write line to log file
        log.write (line)
#close rec file
recFl.close ()
1
  • Of course. The answer is so simple but I couldn't see it. I don't know why I didn't see this.
    – Brad Jones
    Commented Jan 6, 2016 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.