python自動發佈arcgis服務

-- coding: utf-8 --自動發佈mxd到server

Publishes a service to machine myserver using USA.mxd

A connection to ArcGIS Server must be established in the

Catalog window of ArcMap before running this script

Import arcpy module

import arcpy

Define local variables

wrkspc = ‘D:/arcgisdata/’
mapDoc = arcpy.mapping.MapDocument(wrkspc + ‘denggaoxian.mxd’)

Provide path to connection file

To create this file, right-click a folder in the Catalog window and

click New > ArcGIS Server Connection

out_folder_path = wrkspc
con_Filename = “connection.ags”
server_url = “http://192.168.7.42:6080/arcgis/admin
staging_folder_path = wrkspc
username = “siteadmin”
password = “hgdyfb”

arcpy.mapping.CreateGISServerConnectionFile(“ADMINISTER_GIS_SERVICES” ,
out_folder_path,
con_Filename,
server_url,
“ARCGIS_SERVER”,
False,
staging_folder_path,
username,
password,
“SAVE_USERNAME”)

Provide other service details

serviceName = ‘pythonTest’
sddraft = wrkspc + serviceName + ‘.sddraft’
sd = wrkspc + serviceName + ‘.sd’
summary = ‘summary’
tags = ‘tags’

Create service definition draft

arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, serviceName, ‘ARCGIS_SERVER’, con_Filename, True, None, summary, tags)

Analyze the service definition draft

analysis = arcpy.mapping.AnalyzeForSD(sddraft)

Print errors, warnings, and messages returned from the analysis

print “The following information was returned during analysis of the MXD:”
for key in (‘messages’, ‘warnings’, ‘errors’):
print ‘----’ + key.upper() + ‘—’
vars = analysis[key]
for ((message, code), layerlist) in vars.iteritems():
print ’ ‘, message, ’ (CODE %i)’ % code
print ’ applies to:’,
for layer in layerlist:
print layer.name,
print

Stage and upload the service if the sddraft analysis did not contain errors

if analysis[‘errors’] == {}:
# Execute StageService. This creates the service definition.
arcpy.StageService_server(sddraft, sd)

# Execute UploadServiceDefinition. This uploads the service definition and publishes the service.
arcpy.UploadServiceDefinition_server(sd, con_Filename)
print "Service successfully published"

else:
print “Service could not be published because errors were found during analysis.”

print arcpy.GetMessages()

服務器端修改,可以直接替換數據,樣式不用修改

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章