Skip to content

Commit 6a82174

Browse files
committed
update module imports; use formatted string literals; remove uneeded code
1 parent 9b11cc8 commit 6a82174

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

print_errors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
# Created: 08/22/2019
1010
#
11-
# Updated: 1/31/2022
11+
# Updated: 9/21/2022
1212
#-------------------------------------------------------------------------------
1313

1414
import sys
@@ -23,7 +23,7 @@ def print_exception(error):
2323
linecache.checkcache(filename)
2424
line = linecache.getline(filename, lineno, f.f_globals)
2525
# add message
26-
message = '\nError: {}\nFILE: {}, LINE: {}\n\n\t "{}": {}'.format(error, filename, lineno, line.strip(), exc_obj)
26+
message = f'\nError: {error}\nFILE: {filename}, LINE: {lineno}\n\n\t "{line.strip()}": {exc_obj}'
2727
# return to variable
2828
return message
2929
# end PrintException

sde_to_file_geodatabase_replica.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# Created on: 05/12/2016
77
#
8-
# Updated on: 4/26/2022
8+
# Updated on: 9/21/2022
99
#
1010
# Description: Synchronizes updates between a parent and child replica geodatabase in favor of the parent.
1111
# The parent geodatabase is a SDE enterprise geodatabase. The child is a file geodatabase
@@ -15,20 +15,21 @@
1515
# Import system modules
1616
import arcpy
1717
import sys
18-
import datetime
1918
import time
19+
from datetime import date
20+
from os import path
2021

2122
# attempt to run code. if an error occurs, break to except statement
2223
try:
2324
# capture the date the script is being run
24-
date_today = datetime.date.today()
25+
date_today = date.today()
2526
# convert date format to month-day-year (1-1-2020)
2627
formatted_date_today = date_today.strftime("%m-%d-%Y")
2728
# placeholder for messages for text file
2829
log_message = ''
2930
# text file to write messages to
3031
# 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' )
3233

3334
# SDE is parent geodatabase in replication
3435
# TODO: update path for sde connection
@@ -40,25 +41,18 @@
4041
# Process: Synchronize Changes
4142
# Replicates data from parent to child geodatabase
4243
# 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")
4445

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))
5246
# 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"
5448
# If an error occurs running geoprocessing tool(s) capture error and write message
5549
# handle error outside of Python system
5650
except (EnvironmentError, Exception) as e:
5751
tbE = sys.exc_info()[2]
5852
# 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"
6054
# add the error message to the log message
61-
log_message += "\nError: {}\n".format(str(e))
55+
log_message += f"\nError: {str(e)}\n"
6256
finally:
6357
# write message to log file
6458
try:

0 commit comments

Comments
 (0)