ArcGIS Server Administrator API 编写python脚本(二)-----创建站点

0
分享 2014-03-04
本示例介绍了如何根据用户提供的值(主站点管理员帐户、配置存储位置和服务器目录的根位置)创建 ArcGIS Server 站点。这些值与在 ArcGIS Server 管理器中手动创建站点时要求用户输入的值完全相同。代码示例如下:
import httplib, urllib, json
import sys, os
import getpass
def main(argv=None):

#输入用户名和密码信息
username = raw_input("Enter desired primary site administrator name: ")
password = getpass.getpass("Enter desired primary site administrator password: ")
#输入服务器名称
serverName = raw_input("Enter server name: ")
serverPort = 6080
# 输入配置文件路径和服务器目录信息arcgiscache等
configStorePath = raw_input("Enter config store path: ")
rootDirPath = raw_input("Enter root server directory path: ")

# Set up required properties for config store
configStoreConnection={"connectionString": configStorePath, "type": "FILESYSTEM"}

# Set up paths for server directories
cacheDirPath = os.path.join(rootDirPath, "arcgiscache")
jobsDirPath = os.path.join(rootDirPath, "arcgisjobs")
outputDirPath = os.path.join(rootDirPath, "arcgisoutput")
systemDirPath = os.path.join(rootDirPath, "arcgissystem")

# Create Python dictionaries representing server directories
cacheDir = dict(name = "arcgiscache",physicalPath = cacheDirPath,directoryType = "CACHE",cleanupMode = "NONE",maxFileAge = 0,description = "Stores tile caches used by map, globe, and image services for rapid performance.", virtualPath = "")
jobsDir = dict(name = "arcgisjobs",physicalPath = jobsDirPath, directoryType = "JOBS",cleanupMode = "TIME_ELAPSED_SINCE_LAST_MODIFIED",maxFileAge = 360,description = "Stores results and other information from geoprocessing services.", virtualPath = "")
outputDir = dict(name = "arcgisoutput",physicalPath = outputDirPath,directoryType = "OUTPUT",cleanupMode = "TIME_ELAPSED_SINCE_LAST_MODIFIED",maxFileAge = 10,description = "Stores various information generated by services, such as map images.", virtualPath = "")
systemDir = dict(name = "arcgissystem",physicalPath = systemDirPath,directoryType = "SYSTEM",cleanupMode = "NONE",maxFileAge = 0,description = "Stores files that are used internally by the GIS server.", virtualPath = "")

# Serialize directory information to JSON
directoriesJSON = json.dumps(dict(directories = [cacheDir, jobsDir, outputDir, systemDir]))

# Construct URL to create a new site
createNewSiteURL = "/arcgis/admin/createNewSite"

# Set up parameters for the request
params = urllib.urlencode({'username': username, 'password': password, 'configStoreConnection':
configStoreConnection, 'directories':directoriesJSON, 'f': 'json'})

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

# Connect to URL and post parameters
httpConn = httplib.HTTPConnection(serverName, serverPort)
httpConn.request("POST", createNewSiteURL, params, headers)

# Read response
response = httpConn.getresponse()
if (response.status != 200):
httpConn.close()
print "Error while creating the site."
return
else:
data = response.read()
httpConn.close()

# Check that data returned is not an error object
if not assertJsonSuccess(data):
print "Error returned by operation. " + str(data)
else:
print "Site created successfully"

return

# A function that checks that the input JSON object
# is not an error object.
def assertJsonSuccess(data):
obj = json.loads(data)
if 'status' in obj and obj['status'] == "error":
print "Error: JSON object returns an error. " + str(obj)
return False
else:
return True


# Script start
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

文章来源:http://blog.csdn.net/esrichinacd/article/details/8705935

0 个评论

要回复文章请先登录注册