import arcpy
wrkspc = ‘D:/arcgisdata/’
mapDoc = arcpy.mapping.MapDocument(wrkspc + ‘denggaoxian.mxd’)
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”)
serviceName = ‘pythonTest’
sddraft = wrkspc + serviceName + ‘.sddraft’
sd = wrkspc + serviceName + ‘.sd’
summary = ‘summary’
tags = ‘tags’
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, serviceName, ‘ARCGIS_SERVER’, con_Filename, True, None, summary, tags)
analysis = arcpy.mapping.AnalyzeForSD(sddraft)
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
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()
服务器端修改,可以直接替换数据,样式不用修改