Overwriting existing service using ArcPy

3283
2
Jump to solution
11-15-2013 11:31 AM
BetsySchenck-Gardner
Occasional Contributor
I've been trying to figure out how to overwrite an existing service and I found the following code in ArcGIS Server Help:
# Import system modules import arcpy from arcpy import env import xml.dom.minidom as DOM   # Set environment settings env.workspace = "C:/data"  # Set local variables inServiceDefinitionDraft = "myMapService.sddraft" outServiceDefinition = "myMapService.sd" newType = 'esriServiceDefinitionType_Replacement'  xml = draftPath + in_sd_draft doc = DOM.parse(xml) descriptions = doc.getElementsByTagName('Type') for desc in descriptions:     if desc.parentNode.tagName == 'SVCManifest':         if desc.hasChildNodes():             desc.firstChild.data = newType outXml = xml     f = open(outXml, 'w')      doc.writexml( f )      f.close()  # Execute StageService arcpy.StageService_server(inServiceDefinitionDraft, outServiceDefinition)  # Set local variables inSdFile = outServiceDefinition inServer = "GIS Servers/myServerConnection"  # Execute UploadServiceDefinition arcpy.UploadServiceDefinition_server(inSdFile, inServer)


Looks straight forward except for the line "xml = draftPath + in_sd_draft".  Neither one of these variables (draftPath or in_sd_draft) are defined in the script and I don't know what they should be. Would it be c:/Data/myMapService.sddraft? Has anyone tried this script and gotten it to work?

TIA
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BradPosthumus
Occasional Contributor II
You're right, it looks like this one slipped through QA. But the rest of the script can tell you what it should be. Note that I haven't tried the script myself so this is mostly guesswork...

An sddraft file is just an XML file. Within it is a tag that looks like this:

<Type>esriServiceDefinitionType_New</Type>

This script replaces that tag in the sddraft file with this tag:

<Type>esriServiceDefinitionType_Replacement</Type>

I'm assuming this tells ArcGIS Server the service definition file that is created (staged) from this sddraft file will be used to overwrite an existing service when published. So you need to use the inServiceDefinitionDraft as the input for the DOM.parse function, which means you're right, it would be "c:/Data/myMapService.sddraft", or:

xml = env.workspace + "/" + inServiceDefinitionDraft 

View solution in original post

0 Kudos
2 Replies
BradPosthumus
Occasional Contributor II
You're right, it looks like this one slipped through QA. But the rest of the script can tell you what it should be. Note that I haven't tried the script myself so this is mostly guesswork...

An sddraft file is just an XML file. Within it is a tag that looks like this:

<Type>esriServiceDefinitionType_New</Type>

This script replaces that tag in the sddraft file with this tag:

<Type>esriServiceDefinitionType_Replacement</Type>

I'm assuming this tells ArcGIS Server the service definition file that is created (staged) from this sddraft file will be used to overwrite an existing service when published. So you need to use the inServiceDefinitionDraft as the input for the DOM.parse function, which means you're right, it would be "c:/Data/myMapService.sddraft", or:

xml = env.workspace + "/" + inServiceDefinitionDraft 
0 Kudos
BetsySchenck-Gardner
Occasional Contributor
You were correct Brad. Get the script to work once I know what those two variables should be. Thanks.
0 Kudos