Advertisement
Guest User

Untitled

a guest
Apr 1st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. __author__ = 'Administrator'
  2.  
  3. from arcpy import *
  4. import GetSRConfig
  5. import os
  6. import time
  7.  
  8.  
  9. def GetDateTimeString(n = None):
  10. """ format a datetime to string """
  11. if(n==None):
  12. s = time.strftime("%Y%m%d%H%M%S", time.localtime())
  13. else:
  14. s = time.strftime("%Y%m%d%H%M%S", time.localtime())
  15. if((isNumeric(n)==True) and ((n>4) and (n<14))):
  16. s = s[0:n]
  17. else:
  18. s = s[0:14]
  19. return s
  20.  
  21.  
  22.  
  23. def isNumeric(s):
  24. b = True
  25. try:
  26. i = float(s)
  27. except: # not numericelse: # numeric
  28. b= False
  29. return b
  30.  
  31.  
  32. #Locals
  33. P6featureName = GetSRConfig.SDELayer
  34. Parent = "dbo.DEFAULT"
  35. version = "myVersion" + GetDateTimeString(12)
  36. featureLyr = "lyr" + GetDateTimeString(12)
  37.  
  38. print version
  39. # Server = ***
  40. # Service = ***
  41. user ="dbo"
  42. # Pass = ***
  43. # SDE = 'E:C_Drive_filesAdministrator'311RequestdataServiceRequest.sde'
  44. temploc = ""
  45. fil = "SDETempConn"
  46.  
  47. env.overwriteOutput = True
  48.  
  49. #Create Version
  50. print "Creating version"
  51. arcpy.CreateVersion_management (GetSRConfig.SDEConnFile, Parent, version, "PUBLIC")
  52. VersionName = user.upper() + "." + version
  53.  
  54. #Create new connection
  55. workspace = os.path.join (temploc, fil + ".sde")
  56. print workspace
  57. #Layers
  58. P6feature = os.path.join (workspace, P6featureName)
  59. arcpy.MakeFeatureLayer_management (GetSRConfig.SDELayer, featureLyr)
  60.  
  61. #Start editing
  62. print "Initiating editing"
  63. edit = arcpy.da.Editor (GetSRConfig.SDEConnFile)
  64. edit.startEditing ()
  65. edit.startOperation()
  66.  
  67. #Test Cursor
  68. print "Testing cursor"
  69. P6Cursor = arcpy.da.UpdateCursor (featureLyr, ["VehicleNam"])
  70. for row in P6Cursor:
  71. print row[0]
  72. del row
  73. del P6Cursor
  74.  
  75. #Stop/save edits
  76. edit.stopOperation()
  77. print "Stopping editing"
  78. edit.stopEditing("True")
  79.  
  80. #Switch to version
  81. print "Switching version"
  82. arcpy.ChangeVersion_management(featureLyr, "TRANSACTIONAL", Parent)
  83.  
  84. #Reconcile and post
  85. print "Reconciling and posting"
  86. arcpy.ReconcileVersions_management (GetSRConfig.SDEConnFile, "", Parent, VersionName, with_post = "POST", with_delete = "DELETE_VERSION")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement