Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import arcpy, os, sys
  2. ... import xml.dom.minidom as DOM
  3. ...
  4. ... arcpy.env.overwriteOutput = True
  5. ... serviceName = "teritory"
  6. ... tempPath = r"C:msurya"
  7. ...
  8. >>> path2MXD = r"C:msuryateritory.mxd"
  9. ... userName = " "
  10. ... passWord = " "
  11. ...
  12. >>> SDdraft = os.path.join(tempPath, "tempdraft.sddraft")
  13. ... newSDdraft = os.path.join(tempPath, "updatedDraft.sddraft")
  14. ... SD = os.path.join(tempPath, serviceName + ".sd")
  15. ...
  16. >>> arcpy.SignInToPortal_server(userName, passWord, "https://sce2.maps.arcgis.com/")
  17. <Result 'true'>
  18. >>> mxd = arcpy.mapping.MapDocument(path2MXD)
  19. ... arcpy.mapping.CreateMapSDDraft(mxd, SDdraft, serviceName, "MY_HOSTED_SERVICES")
  20. ...
  21. >>> doc = DOM.parse(SDdraft)
  22. >>> tagsType = doc.getElementsByTagName('Type')
  23. ... for tagType in tagsType:
  24. ... if tagType.parentNode.tagName == 'SVCManifest':
  25. ... if tagType.hasChildNodes():
  26. ... tagType.firstChild.data = "esriServiceDefinitionType_Replacement"
  27. ... tagsState = doc.getElementsByTagName('State')
  28. ... for tagState in tagsState:
  29. ... if tagState.parentNode.tagName == 'SVCManifest':
  30. ... if tagState.hasChildNodes():
  31. ... tagState.firstChild.data = "esriSDState_Published"
  32. ...
  33. ... # Change service type from map service to feature service
  34. ... typeNames = doc.getElementsByTagName('TypeName')
  35. ... for typeName in typeNames:
  36. ... if typeName.firstChild.data == "MapServer":
  37. ... typeName.firstChild.data = "FeatureServer"
  38. ... configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
  39. ... propArray = configProps.firstChild
  40. ... propSets = propArray.childNodes
  41. ... for propSet in propSets:
  42. ... keyValues = propSet.childNodes
  43. ... for keyValue in keyValues:
  44. ... if keyValue.tagName == 'Key':
  45. ... if keyValue.firstChild.data == "isCached":
  46. ... keyValue.nextSibling.firstChild.data = "false"
  47. ... configProps = doc.getElementsByTagName('Info')[0]
  48. ... propArray = configProps.firstChild
  49. ... propSets = propArray.childNodes
  50. ... for propSet in propSets:
  51. ... keyValues = propSet.childNodes
  52. ... for keyValue in keyValues:
  53. ... if keyValue.tagName == 'Key':
  54. ... if keyValue.firstChild.data == "WebCapabilities":
  55. ... keyValue.nextSibling.firstChild.data = "Query,Create,Update,Delete,Uploads,Editing"
  56. ...
  57. >>> f = open(newSDdraft, 'w')
  58. ... doc.writexml( f )
  59. ... f.close()
  60. ... analysis = arcpy.mapping.AnalyzeForSD(newSDdraft)
  61. ...
  62. >>> if analysis['errors'] == {}:
  63. ... # Stage the service
  64. ... arcpy.StageService_server(newSDdraft, SD)
  65. ...
  66. >>> arcpy.UploadServiceDefinition_server(SD,"My Hosted Services",serviceName,"","","","","OVERRIDE_DEFINITION","SHARE_ONLINE","PUBLIC","SHARE_ORGANIZATION","")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement