|
5 | 5 | #
|
6 | 6 | # Created on: 05/12/2016
|
7 | 7 | #
|
8 |
| -# Updated on: 4/26/2022 |
| 8 | +# Updated on: 9/21/2022 |
9 | 9 | #
|
10 | 10 | # Description: Synchronizes updates between a parent and child replica geodatabase in favor of the parent.
|
11 | 11 | # The parent geodatabase is a SDE enterprise geodatabase. The child is a file geodatabase
|
|
15 | 15 | # Import system modules
|
16 | 16 | import arcpy
|
17 | 17 | import sys
|
18 |
| -import datetime |
19 | 18 | import time
|
| 19 | +from datetime import date |
| 20 | +from os import path |
20 | 21 |
|
21 | 22 | # attempt to run code. if an error occurs, break to except statement
|
22 | 23 | try:
|
23 | 24 | # capture the date the script is being run
|
24 |
| - date_today = datetime.date.today() |
| 25 | + date_today = date.today() |
25 | 26 | # convert date format to month-day-year (1-1-2020)
|
26 | 27 | formatted_date_today = date_today.strftime("%m-%d-%Y")
|
27 | 28 | # placeholder for messages for text file
|
28 | 29 | log_message = ''
|
29 | 30 | # text file to write messages to
|
30 | 31 | # TODO: update path
|
31 |
| - log_file = r'C:\GIS\Results\Database_Maint_Report_{}.txt'.format(date_today) |
| 32 | + log_file = path.join( r'C:\GIS\Results', f'Database_Maint_Report_{formatted_date_today}.txt' ) |
32 | 33 |
|
33 | 34 | # SDE is parent geodatabase in replication
|
34 | 35 | # TODO: update path for sde connection
|
|
40 | 41 | # Process: Synchronize Changes
|
41 | 42 | # Replicates data from parent to child geodatabase
|
42 | 43 | # TODO: update the name of the replication
|
43 |
| - result = arcpy.SynchronizeChanges_management(sde, "Name of Replication", child_gdb, "FROM_GEODATABASE1_TO_2", "IN_FAVOR_OF_GDB1", "BY_OBJECT", "DO_NOT_RECONCILE") |
| 44 | + arcpy.SynchronizeChanges_management(sde, "Name of Replication", child_gdb, "FROM_GEODATABASE1_TO_2", "IN_FAVOR_OF_GDB1", "BY_OBJECT", "DO_NOT_RECONCILE") |
44 | 45 |
|
45 |
| - # delay writing results until geoprocessing tool gets the completed code |
46 |
| - while result.status < 4: |
47 |
| - time.sleep(0.2) |
48 |
| - # store tool result message in a variable |
49 |
| - resultValue = result.getMessages() |
50 |
| - # add the tool's message to the log message |
51 |
| - log_message += "completed {}\n".format(str(resultValue)) |
52 | 46 | # add a more human readable message to log message
|
53 |
| - log_message += "\nSuccessfully ran replication from {} to {} on {}\n".format(sde, child_gdb, formatted_date_today) |
| 47 | + log_message += f"\nSuccessfully ran replication from {sde} to {child_gdb} on {formatted_date_today}\n" |
54 | 48 | # If an error occurs running geoprocessing tool(s) capture error and write message
|
55 | 49 | # handle error outside of Python system
|
56 | 50 | except (EnvironmentError, Exception) as e:
|
57 | 51 | tbE = sys.exc_info()[2]
|
58 | 52 | # add the line number the error occured to the log message
|
59 |
| - log_message += "\nFailed at Line {}\n".format(tbE.tb_lineno) |
| 53 | + log_message += f"\nFailed at Line {tbE.tb_lineno}\n" |
60 | 54 | # add the error message to the log message
|
61 |
| - log_message += "\nError: {}\n".format(str(e)) |
| 55 | + log_message += f"\nError: {str(e)}\n" |
62 | 56 | finally:
|
63 | 57 | # write message to log file
|
64 | 58 | try:
|
|
0 commit comments