#coding=utf-8
import arcpy
import arcpy.mapping as mapping
import os
import sys
ws = r'd:\out'
mdpath = os.path.join(ws, r'彩票店数量300m内1.tif')
con = os.path.join(ws, r'connection.ags')
service = 'lottery'
sddraft = os.path.join(ws, service + '.sddraft')
arcpy.CreateImageSDDraft(mdpath, sddraft, service, 'ARCGIS_SERVER',
con, True, None, "Publish las MD",
"las,image service")
sd = os.path.join(ws, service+".sd")
analysis = arcpy.mapping.AnalyzeForSD(sddraft)
if analysis['errors'] == {}:
try:
print 'stage..'
arcpy.StageService_server(sddraft, sd)
arcpy.UploadServiceDefinition_server(sd, con)
print "Service successfully published"
except arcpy.ExecuteError:
print 'error:'
print(arcpy.GetMessages() + "\n\n")
except Exception as err:
print(err[0] + "\n\n")
sys.exit("Failed to stage and upload service")
else:
print(analysis['errors'])


