Created
December 13, 2013 10:35
-
-
Save sofferm/7942506 to your computer and use it in GitHub Desktop.
Publishes all mxd files in a folder to running arcgis services.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy | |
import os.path | |
# define local variables | |
wrkspc = r'C:\data\service_definitions' | |
arcpy.env.workspace = wrkspc | |
con = 'GIS Servers/arcgis on localhost_6080 (admin).ags' | |
for file in arcpy.ListFiles("*.mxd"): | |
file = os.path.join(wrkspc, file) | |
mapDoc = arcpy.mapping.MapDocument(file) | |
service = os.path.splitext(os.path.basename(file))[0] | |
sddraft = os.path.join(wrkspc, service + '.sddraft') | |
sd = os.path.join(wrkspc, service + '.sd') | |
summary = service | |
tags = 'my service' | |
# create service definition draft | |
analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', | |
None, False, 'property', summary, tags) | |
# stage and upload the service if the sddraft analysis did not contain errors | |
if analysis['errors'] == {}: | |
# Execute StageService | |
arcpy.StageService_server(sddraft, sd) | |
# Execute UploadServiceDefinition | |
arcpy.UploadServiceDefinition_server(sd, con) | |
else: | |
# if the sddraft analysis contained errors, display them | |
print analysis['errors'] | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment