There was a few errors while trying to process data involving the Network Transfer tool and the output GDBs. Andrea has made some changes below and to answer the questions in the code:
If we do not return out of the first exception block the only issue with it trying to copy over features from the source to the destination it was trying to generate would be if it failed before it even creates the gdb then it will just fail out of that again.
The deleting of the local gdb is handled all in the spatial transformer code, so there would need to be a boolean that gets passed back to spatial transformer to tell the program whether it succeeded or not (whether to delete the local or not)
These two things need to be addressed and fixed.
def merge_gdbs(src_gdb: str, dest_gdb: str, log_path: str = None) -> None:
"""
Merge source Geodatabase into destination Geodatabase.
Args:
src_gdb (str): Path to the source Geodatabase.
dest_gdb (str): Path to the destination Geodatabase.
log_path (str): path to the log file.
"""
# Set the workplace for the source geodatabase
arcpy.env.workspace = src_gdb
try:
# Copy the whole GDB if it does not exist
if not arcpy.Exists(dest_gdb):
if not os.path.exists(os.path.dirname(dest_gdb)):
os.mkdir(os.path.dirname(dest_gdb))
arcpy.management.Copy(
src_gdb,
dest_gdb
)
log(None, Colors.INFO, f'Copy to {dest_gdb} has completed.')
return
except Exception as error:
log(log_path, Colors.ERROR, f'An error has been caught while trying to copy the geodatabase to {dest_gdb}: {error}')
return # do we need to return here or does the program fail?
# Get a list of feature classes in the source geodatabase
feature_classes = arcpy.ListFeatureClasses()
for feature_class in feature_classes:
try:
# Skip if already exists in destination
if arcpy.Exists(os.path.join(dest_gdb, feature_class)):
continue
arcpy.management.Copy(
os.path.join(src_gdb, feature_class),
os.path.join(dest_gdb, feature_class)
)
log(None, Colors.INFO, f'Merging to {dest_gdb} has completed.')
except Exception as error:
log(log_path, Colors.ERROR, f'An error has been caught while trying to merge the geodatabase to {dest_gdb}: {error}')
#TODO if error occurs while copying an individual file then do not delete the C:/Local... GDB
a new return value is added to the network transfer to determine if there was an error when moving the GDB from the local dir to the network. If an issue was caught then it will not delete the local anymore
There was a few errors while trying to process data involving the Network Transfer tool and the output GDBs. Andrea has made some changes below and to answer the questions in the code:
These two things need to be addressed and fixed.