#-*-coding:utf-8
__author__ = 'suwen'
import os
import arcpy
def CreateContectionFile(wrkspc,userName,password,serverName):
# con = 'http://localhost:6080/arcgis/admin'
con="http://"+str(serverName)+":6080/arcgis/admin"
connection_file_path=str(wrkspc)+"/tmp.ags"
#
if os.path.exists(connection_file_path):
os.remove(connection_file_path)
agsname=os.path.basename(connection_file_path)
arcpy.mapping.CreateGISServerConnectionFile("ADMINISTER_GIS_SERVICES",
wrkspc,
agsname,
con,
"ARCGIS_SERVER",
username=userName,
password=password,
save_username_password=True)
return connection_file_path
def PublishService(connection_file_path,wrkspc,mapDoc):
#get the serviceName
serviceName =os.path.basename(mapDoc).replace(".mxd","")
#create the .sddraft path
sddraftname=os.path.basename(mapDoc).replace(".mxd",".sddraft")
sddraft =str(wrkspc)+"/"+str(sddraftname)
#create the .sd file path
sdname=os.path.basename(mapDoc).replace(".mxd",".sd")
sd=str(wrkspc)+"/"+str(sdname)
#check the file exists or not
if(os.path.exists(sd)):
os.remove(sd)
analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, serviceName, 'ARCGIS_SERVER',
connection_file_path, True, None,None,None)
arcpy.StageService_server(sddraft, sd)
arcpy.UploadServiceDefinition_server(sd, connection_file_path)
connection_file_path="C:\Users\suwen\AppData\Local\Esri\Desktop10.2\Staging"
mxdfolder=u"D:\数据\china"
userName="arcgis"
password="arcgis"
serverName="192.168.220.64"
wrkspc=r"d:\数据\china"
connection_file_path=CreateContectionFile(wrkspc,userName,password,serverName)
# the mxd file list of the mxdPath
mxds=os.listdir(mxdfolder)
mxd_files=[]
for file in mxds:
if file.endswith(".mxd"):
mxdpath=os.path.join(mxdfolder,file)
mxd_files.append(mxdpath)
for mxd in mxd_files:
PublishService(connection_file_path,wrkspc,mxd)
__author__ = 'suwen'
import os
import arcpy
def CreateContectionFile(wrkspc,userName,password,serverName):
# con = 'http://localhost:6080/arcgis/admin'
con="http://"+str(serverName)+":6080/arcgis/admin"
connection_file_path=str(wrkspc)+"/tmp.ags"
#
if os.path.exists(connection_file_path):
os.remove(connection_file_path)
agsname=os.path.basename(connection_file_path)
arcpy.mapping.CreateGISServerConnectionFile("ADMINISTER_GIS_SERVICES",
wrkspc,
agsname,
con,
"ARCGIS_SERVER",
username=userName,
password=password,
save_username_password=True)
return connection_file_path
def PublishService(connection_file_path,wrkspc,mapDoc):
#get the serviceName
serviceName =os.path.basename(mapDoc).replace(".mxd","")
#create the .sddraft path
sddraftname=os.path.basename(mapDoc).replace(".mxd",".sddraft")
sddraft =str(wrkspc)+"/"+str(sddraftname)
#create the .sd file path
sdname=os.path.basename(mapDoc).replace(".mxd",".sd")
sd=str(wrkspc)+"/"+str(sdname)
#check the file exists or not
if(os.path.exists(sd)):
os.remove(sd)
analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, serviceName, 'ARCGIS_SERVER',
connection_file_path, True, None,None,None)
arcpy.StageService_server(sddraft, sd)
arcpy.UploadServiceDefinition_server(sd, connection_file_path)
connection_file_path="C:\Users\suwen\AppData\Local\Esri\Desktop10.2\Staging"
mxdfolder=u"D:\数据\china"
userName="arcgis"
password="arcgis"
serverName="192.168.220.64"
wrkspc=r"d:\数据\china"
connection_file_path=CreateContectionFile(wrkspc,userName,password,serverName)
# the mxd file list of the mxdPath
mxds=os.listdir(mxdfolder)
mxd_files=[]
for file in mxds:
if file.endswith(".mxd"):
mxdpath=os.path.join(mxdfolder,file)
mxd_files.append(mxdpath)
for mxd in mxd_files:
PublishService(connection_file_path,wrkspc,mxd)