Solved! Go to Solution.
import arcpy import xml.dom.minidom as DOM import os workspace = 'C:/Temp/hosted publishing/' # Reference map document for CreateSDDraft function. mapDoc = arcpy.mapping.MapDocument(r'C:\Temp\betty4.mxd') # Create service and sddraft variables for CreateSDDraft function. sddraft = workspace + 'HostedMS.sddraft' service = 'FeatureService' arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'MY_HOSTED_SERVICES', summary="test", tags='test') con = 'My Hosted Services' sd = workspace + service + '.sd' doc = DOM.parse(sddraft) # Read the sddraft xml. doc = DOM.parse(sddraft) # Change service from map service to feature service typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: # Get the TypeName we want to disable. if typeName.firstChild.data == "MapServer": typeName.firstChild.data = "FeatureServer" #Turn off caching configProps = doc.getElementsByTagName('ConfigurationProperties')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "isCached": # turn on caching keyValue.nextSibling.firstChild.data = "false" #Turn on feature access capabilities configProps = doc.getElementsByTagName('Info')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "WebCapabilities": # turn on caching keyValue.nextSibling.firstChild.data = "Query,Create,Update,Delete,Uploads,Editing" outXml = workspace + 'HostedMSNew.sddraft' f = open(outXml, 'w') doc.writexml( f ) f.close() analysis = arcpy.mapping.AnalyzeForSD(outXml) #print analysis #arcpy.SignOutFromPortal_server() arcpy.SignInToPortal_server("username","password","http://www.arcgis.com/") arcpy.StageService_server(outXml, sd) arcpy.UploadServiceDefinition_server(sd, con)
import arcpy import xml.dom.minidom as DOM import os workspace = 'C:/Temp/hosted publishing/' # Reference map document for CreateSDDraft function. mapDoc = arcpy.mapping.MapDocument(r'C:\Temp\betty4.mxd') # Create service and sddraft variables for CreateSDDraft function. sddraft = workspace + 'HostedMS.sddraft' service = 'FeatureService' arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'MY_HOSTED_SERVICES', summary="test", tags='test') con = 'My Hosted Services' sd = workspace + service + '.sd' doc = DOM.parse(sddraft) # Read the sddraft xml. doc = DOM.parse(sddraft) # Change service from map service to feature service typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: # Get the TypeName we want to disable. if typeName.firstChild.data == "MapServer": typeName.firstChild.data = "FeatureServer" #Turn off caching configProps = doc.getElementsByTagName('ConfigurationProperties')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "isCached": # turn on caching keyValue.nextSibling.firstChild.data = "false" #Turn on feature access capabilities configProps = doc.getElementsByTagName('Info')[0] propArray = configProps.firstChild propSets = propArray.childNodes for propSet in propSets: keyValues = propSet.childNodes for keyValue in keyValues: if keyValue.tagName == 'Key': if keyValue.firstChild.data == "WebCapabilities": # turn on caching keyValue.nextSibling.firstChild.data = "Query,Create,Update,Delete,Uploads,Editing" outXml = workspace + 'HostedMSNew.sddraft' f = open(outXml, 'w') doc.writexml( f ) f.close() analysis = arcpy.mapping.AnalyzeForSD(outXml) #print analysis #arcpy.SignOutFromPortal_server() arcpy.SignInToPortal_server("username","password","http://www.arcgis.com/") arcpy.StageService_server(outXml, sd) arcpy.UploadServiceDefinition_server(sd, con)
Hey Jeff,
Could you please share the code in a little nicer way to look at it?
I am very new to python and I am trying to step my way through the code but I cant seem to separate it our very well since its all in a line.
Thanks
Is there a way get this code in actual lines of code rather than one enormously large single line of code? I'm guessing there is a browser SNAFU. But IE, FF and Chrome are all currently displaying your response as a single line of code.
typeReplace = 'esriServiceDefinitionType_Replacement' statePublished = 'esriSDState_Published' myTagsType = doc.getElementsByTagName('Type') for myTagType in myTagsType: if myTagType.parentNode.tagName == 'SVCManifest': if myTagType.hasChildNodes(): myTagType.firstChild.data = typeReplace myTagsState = doc.getElementsByTagName('State') for myTagState in myTagsState: if myTagState.parentNode.tagName == 'SVCManifest': if myTagState.hasChildNodes(): myTagState.firstChild.data = statePublished
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Server: Dataset My Hosted Services does not exist or is not supported Failed to execute (UploadServiceDefinition).