Skip To Content

Пример. Публикация сервисов различных типов с помощью определений сервисов

Определение сервиса (SD-файл) заключает сервис в один передаваемый файл, при необходимости включающий исходные ГИС-данные. Затем инструмент Передать определение сервиса (Upload Service Definition) передает определение сервиса на сервер и публикует его. Его можно вызывать из пакета сайта arcpy, включенного в ArcGIS Desktop.

В следующем примере Python выполняется циклический перебор элементов папки, в ней находятся определения сервисов (вложенные папки не рассматриваются), которые публикуются в ArcGIS for Server. Требуется только указать расположение данных, путь к файлу подключения ArcGIS for Server и имя целевой папки в ArcGIS for Server. Определения сервисов могут быть любого типа.

# Publishes all service definitions in an operating system directory
#  (excluding subfolders)
import arcpy, os

# Define path to SDs
wrkspc = "C:/data"
sdDir = wrkspc + "/SDs"

# Provide path to connection file
# To create this file, right-click a folder in the Catalog window and
#  click New > ArcGIS Server Connection
con = wrkspc + "/connections/arcgis on myserver_6080 (publisher).ags"

# Destination folder name on ArcGIS Server
serverFolder = "TestPublish"

# Loop through all items in folder
sdList = os.listdir(sdDir)

for sd in sdList:
    
    # Construct path to item
    extension = os.path.splitext(sd)[1] #Get file extension
    sdPath = os.path.join(sdDir, sd)

    # Check if item is an SD file and, if so, try to publish
    if os.path.isfile(sdPath) and extension == ".sd":    
        try:     
            arcpy.UploadServiceDefinition_server(sdPath, con, "", "", "EXISTING", serverFolder)
            print "Published " + sd + " with no errors reported."
            
        except:
            print "Could not complete publishing operation for " + sd + "."

        print arcpy.GetMessages()