update-prod-from-dev-hobart.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. '''
  2. Truncate/Delete Rows and Append
  3. tool for Hobart, IN features. '''
  4. import arcpy
  5. def replaceData(input_fc, target_fc):
  6. arcpy.AddMessage('Starting run...')
  7. input_row_count = int(arcpy.GetCount_management(input_fc)[0])
  8. et_switch = 0
  9. desc = arcpy.da.Describe(target_fc)
  10. if desc['editorTrackingEnabled']:
  11. arcpy.AddMessage('Editor tracking is enabled...')
  12. et_switch = 1
  13. arcpy.AddMessage('Identifying ET fields...')
  14. creator_fld = desc['creatorFieldName']
  15. create_date_fld = desc['createdAtFieldName']
  16. editor_fld = desc['editorFieldName']
  17. edit_date_fld= desc['editedAtFieldName']
  18. arcpy.AddMessage('Disabling editor tracking...')
  19. arcpy.DisableEditorTracking_management(target_fc, 'DISABLE_CREATOR', 'DISABLE_CREATION_DATE', 'DISABLE_LAST_EDITOR', 'DISABLE_LAST_EDIT_DATE')
  20. if desc['isVersioned']:
  21. arcpy.AddMessage('Dataset is versioned...')
  22. arcpy.AddMessage('Deleting rows...')
  23. arcpy.DeleteRows_management(target_fc)
  24. arcpy.AddMessage('Appending updated data...')
  25. arcpy.Append_management(input_fc, target_fc, 'NO_TEST')
  26. if et_switch == 1:
  27. arcpy.AddMessage('Enabling editor tacking...')
  28. arcpy.EnableEditorTracking_management(target_fc, creator_fld, create_date_fld, editor_fld, edit_date_fld, 'NO_ADD_FIELDS')
  29. else:
  30. arcpy.AddMessage('Truncating dataset...')
  31. arcpy.TruncateTable_management(target_fc)
  32. arcpy.AddMessage('Appending updated data...')
  33. arcpy.Append_management(input_fc, target_fc, 'NO_TEST')
  34. if et_switch == 1:
  35. arcpy.AddMessage('Enabling editor tacking...')
  36. arcpy.EnableEditorTracking_management(target_fc, creator_fld, create_date_fld, editor_fld, edit_date_fld, 'NO_ADD_FIELDS')
  37. target_row_count = int(arcpy.GetCount_management(target_fc)[0])
  38. if input_row_count == target_row_count:
  39. arcpy.AddMessage('Done!')
  40. else:
  41. arcpy.AddWarning('Row counts from input and target do not match!')
  42. arcpy.AddWarning('Manual investigation is required!')
  43. arcpy.AddWarning('Compare field lengths and types to ensure the schemas match.')
  44. if __name__ == '__main__':
  45. dev_fc = arcpy.GetParameterAsText(0)
  46. prod_fc = arcpy.GetParameterAsText(1)
  47. try:
  48. replaceData(dev_fc, prod_fc)
  49. except Exception as e:
  50. arcpy.AddWarning(e)
  51. arcpy.AddError('Run failed :(')