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

来源:互联网 发布:维多利亚贝克汉姆 知乎 编辑:程序博客网 时间:2024/05/03 21:31

     本示例介绍了如何根据用户提供的值(主站点管理员帐户、配置存储位置和服务器目录的根位置)创建 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:]))

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小学三年级数学60多分怎么办 孩子三年级了数学不开窍怎么办 初二数学太差该怎么办 孩子语文阅读理解能力差怎么办 5年级数学不开窍怎么办 一年级孩子数学不开窍怎么办 三年级孩子数学成绩差怎么办 孩子三年级数学太差怎么办 三年级孩子数学理解能力差怎么办 教小孩做作业老是发火怎么办 孩子拿笔重写字太黑怎么办 教小孩写不到汉字怎么办 一年级孩子数学理解能力差怎么办 小孩一年级数学学不好怎么办 孩子一年级数学学不好怎么办 小学一年级数学学不好怎么办 孩子一年级数学成绩不好怎么办 成绩差的孩子该怎么办 面对成绩差的孩子该怎么办 六年级数学成绩差该怎么办 孩子数学物理成绩差该怎么办 高三成绩很差该怎么办 孩子学习成绩差家长该怎么办 孩子一年级语文成绩不好怎么办 孩子上网成瘾不听父母话怎么办 10岁数学不开窍怎么办 孩子五年级数学不好怎么办 一岁宝宝难断奶怎么办 2岁宝宝断不了奶怎么办 快2岁宝宝不听话怎么办 2岁半的宝宝不听话怎么办 3岁宝宝哭闹不止怎么办 2岁宝宝爱打人怎么办 两周岁宝宝吃东西就吐怎么办 两周岁宝宝不爱吃饭怎么办 两周岁宝宝反复发烧怎么办 两周岁宝宝咳嗽厉害怎么办 2岁宝宝体内有火怎么办 4岁宝宝数都不会怎么办 两岁宝宝太撅怎么办 儿童晚上发烧白天不发烧怎么办