Guest User

Untitled

a guest
Aug 23rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. def build_connection_file():
  2. """This function handles everything involved in building a connection
  3. file to the manhole feature class in sewer"""
  4.  
  5. directory = r"C:TempConnectionFiles"
  6. if not os.path.isdir(directory):
  7. os.path.makedirs(directory)
  8.  
  9. feature_dataset = r"ThisIsReal"
  10. feature_class = r"ThisIsReal"
  11.  
  12. sde = r"Database ConnectionsReal.sde"
  13.  
  14. versions = [version.name for version in arcpy.da.ListVersions(manhole_sde)
  15. if (getpass.getuser() in version.name)]
  16.  
  17. print versions[-1]
  18.  
  19. connection_name = "ThisIsReal.sde"
  20. if not os.path.isfile(os.path.join(directory, connection_name)):
  21. arcpy.CreateDatabaseConnection_management(
  22. out_folder_path = directory,
  23. out_name = connection_name,
  24. database_platform = "real_platform",
  25. instance = "real_instance",
  26. account_authentication = "OPERATING_SYSTEM_AUTH",
  27. username = "",
  28. password = "",
  29. save_user_pass = "DO_NOT_SAVE_USERNAME",
  30. database = "real_database",
  31. version_type = "TRANSACTIONAL",
  32. version = versions[-1])
  33.  
  34. connection_feature_class_full = os.path.join(
  35. directory, connection_name, feature_dataset,
  36. feature_class)
  37.  
  38. print connection_feature_class_full
  39.  
  40. #this was required last time I did this.
  41. table_view = arcpy.MakeTableView_management(
  42. in_table = connection_feature_class_full,
  43. out_view = r"connection_table", where_clause = "",
  44. workspace ="", field_info = "")
  45.  
  46. arcpy.ChangeVersion_management(
  47. in_features = table_view, version_type = "TRANSACTIONAL",
  48. version_name = versions[-1], date = '')
  49.  
  50. print("changed version")
  51.  
  52. return connection_feature_class_full
  53.  
  54. connection_feature_class = build_connection_file()
  55. edit = arcpy.da.Editor(manhole_connection_feature_class_full)
  56. edit.startEditing(True, False)
  57. edit.startOperation()
Add Comment
Please, Sign In to add comment