Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Administrator'
- from arcpy import *
- import GetSRConfig
- import os
- import time
- def GetDateTimeString(n = None):
- """ format a datetime to string """
- if(n==None):
- s = time.strftime("%Y%m%d%H%M%S", time.localtime())
- else:
- s = time.strftime("%Y%m%d%H%M%S", time.localtime())
- if((isNumeric(n)==True) and ((n>4) and (n<14))):
- s = s[0:n]
- else:
- s = s[0:14]
- return s
- def isNumeric(s):
- b = True
- try:
- i = float(s)
- except: # not numericelse: # numeric
- b= False
- return b
- #Locals
- P6featureName = GetSRConfig.SDELayer
- Parent = "dbo.DEFAULT"
- version = "myVersion" + GetDateTimeString(12)
- featureLyr = "lyr" + GetDateTimeString(12)
- print version
- # Server = ***
- # Service = ***
- user ="dbo"
- # Pass = ***
- # SDE = 'E:C_Drive_filesAdministrator'311RequestdataServiceRequest.sde'
- temploc = ""
- fil = "SDETempConn"
- env.overwriteOutput = True
- #Create Version
- print "Creating version"
- arcpy.CreateVersion_management (GetSRConfig.SDEConnFile, Parent, version, "PUBLIC")
- VersionName = user.upper() + "." + version
- #Create new connection
- workspace = os.path.join (temploc, fil + ".sde")
- print workspace
- #Layers
- P6feature = os.path.join (workspace, P6featureName)
- arcpy.MakeFeatureLayer_management (GetSRConfig.SDELayer, featureLyr)
- #Start editing
- print "Initiating editing"
- edit = arcpy.da.Editor (GetSRConfig.SDEConnFile)
- edit.startEditing ()
- edit.startOperation()
- #Test Cursor
- print "Testing cursor"
- P6Cursor = arcpy.da.UpdateCursor (featureLyr, ["VehicleNam"])
- for row in P6Cursor:
- print row[0]
- del row
- del P6Cursor
- #Stop/save edits
- edit.stopOperation()
- print "Stopping editing"
- edit.stopEditing("True")
- #Switch to version
- print "Switching version"
- arcpy.ChangeVersion_management(featureLyr, "TRANSACTIONAL", Parent)
- #Reconcile and post
- print "Reconciling and posting"
- arcpy.ReconcileVersions_management (GetSRConfig.SDEConnFile, "", Parent, VersionName, with_post = "POST", with_delete = "DELETE_VERSION")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement