Example #1
0
def manage_service(host_type, service_path, operation):

    if host_type == "dev":
        host = "http://localhost"
        cred = settings.get_ini_file("arcgis_server_dm", "tokens")

    elif host_type == "prod":
        host = "http://gis-gfw.wri.org/arcgis"
        cred = settings.get_ini_file("arcgis_server_prod", "tokens")

    else:
        logging.error("Invalid service type for manage_service. Exiting")
        sys.exit(1)

    service_utility = r"C:\Program Files\ArcGIS\Server\tools\admin\manageservice.py"

    path_split = service_path.split("\\")
    name = "/".join(path_split[-2:]).replace(".MapServer", "")

    cmd = [
        "python",
        service_utility,
        "-u",
        cred["username"],
        "-p",
        cred["password"],
        "-s",
        host,
        "-n",
        name,
        "-o",
        operation,
    ]
    subprocess.check_call(cmd)
def manage_service(host_type, service_path, operation):

    if host_type == 'dev':
        host = 'http://localhost'
        cred = settings.get_ini_file('arcgis_server_dm', 'tokens')

    elif host_type == 'prod':
        host = 'http://gis-gfw.wri.org/arcgis'
        cred = settings.get_ini_file('arcgis_server_prod', 'tokens')

    else:
        logging.error('Invalid service type for manage_service. Exiting')
        sys.exit(1)

    service_utility = r"C:\Program Files\ArcGIS\Server\tools\admin\manageservice.py"

    path_split = service_path.split('\\')
    name = '/'.join(path_split[-2:]).replace('.MapServer', '')

    python_exe = r'C:\PYTHON27\ArcGISx6410.5\python'
    cmd = [
        python_exe, service_utility, '-u', cred['username'], '-p',
        cred['password'], '-s', host, '-n', name, '-o', operation
    ]
    subprocess.check_call(cmd)
def manage_service(host_type, service_path, operation):

    if host_type == 'dev':
        host = 'http://localhost'
        cred = settings.get_ini_file('arcgis_server_dm', 'tokens')

    elif host_type == 'prod':
        host = 'http://gis-gfw.wri.org/arcgis'
        cred = settings.get_ini_file('arcgis_server_prod', 'tokens')

    else:
        logging.error('Invalid service type for manage_service. Exiting')
        sys.exit(1)

    service_utility = r"C:\Program Files\ArcGIS\Server\tools\admin\manageservice.py"

    path_split = service_path.split('\\')
    name = '/'.join(path_split[-2:]).replace('.MapServer', '')

    cmd = ['python', service_utility, '-u', cred['username'], '-p', cred['password'],
           '-s', host, '-n', name, '-o', operation]
    subprocess.check_call(cmd)
Example #4
0
def find_src_mxd_and_cache_dir(map_service_path):
    """
    Use the admin REST endpoint to get info about the source MXD location and the cache directory
    :param map_service_path:
    :return:
    """

    # http://server.arcgis.com/en/server/latest/administer/linux/example-edit-service-properties.htm
    cred = settings.get_ini_file('arcgis_server_dm', 'tokens')
    token = request_token(cred)

    # Need to convert the path from our gis server (map_service_path) to its URL
    # map_service_path example: GIS Servers\arcgis on gis-gfw.wri.org (admin)\cached\temp_cached_mapservice.MapServer
    try:
        partial_path = map_service_path.split('gis-gfw.wri.org')[1]

    except IndexError:
        partial_path = map_service_path.split('localhost')[1]

    paren_index = partial_path.index(')')

    # Start at the paren index and grab the rest of the path
    map_service = partial_path[paren_index+2:]

    # convert windows path to internet path
    map_service = map_service.replace('''\\''', '/')

    base_url = r'http://localhost:6080/arcgis/admin/services/{0}'
    url = urlparse.urljoin(base_url, map_service)

    payload = {"token": token, "f": "json"}
    r = requests.get(url, params=payload)

    if r.status_code != 200:
        logging.error("Bad JSON response. Status {0}, content {1]".format(r.status_code, r.content))
        sys.exit(1)

    else:
        response = json.loads(r.content)

        source_mxd = find_src_mxd(response)
        cache_dir = find_cache_dir(response)

    return source_mxd, cache_dir
def find_src_mxd_and_cache_dir(map_service_path):
    """
    Use the admin REST endpoint to get info about the source MXD location and the cache directory
    :param map_service_path:
    :return:
    """

    # http://server.arcgis.com/en/server/latest/administer/linux/example-edit-service-properties.htm
    cred = settings.get_ini_file('arcgis_server_dm', 'tokens')
    token = request_token(cred)

    # Need to convert the path from our gis server (map_service_path) to its URL
    # map_service_path example: GIS Servers\arcgis on gis-gfw.wri.org (admin)\cached\temp_cached_mapservice.MapServer
    try:
        partial_path = map_service_path.split('gis-gfw.wri.org')[1]

    except IndexError:
        partial_path = map_service_path.split('localhost')[1]

    paren_index = partial_path.index(')')

    # Start at the paren index and grab the rest of the path
    map_service = partial_path[paren_index+2:]

    base_url = r'http://localhost/arcgis/admin/services/{0}'
    url = urlparse.urljoin(base_url, map_service)

    payload = {"token": token, "f": "json"}
    r = requests.get(url, params=payload)

    if r.status_code != 200:
        logging.error("Bad JSON response. Status {0}, content {1]".format(r.status_code, r.content))
        sys.exit(1)

    else:
        response = json.loads(r.content)

        source_mxd = find_src_mxd(response)

        # TODO BUILD THIS OUT
        cache_dir = find_cache_dir(response)

    return source_mxd, cache_dir