def get_service_portal_ids(server, port, user, password): service_portal_ids = None # Get list of services on specified ArcGIS Server service_list = getServiceList(server, port, user, password) if len(service_list) > 0: service_portal_ids = {} # Get ids for all portal items assocatied with each AGS service for service in service_list: parsed_service = service.split('//') folder = None if len(parsed_service) == 1: service_name_type = parsed_service[0] else: folder = parsed_service[0] service_name_type = parsed_service[1] service_portal_prop = getServicePortalProps(server, port, user, password, folder, service_name_type) service_portal_items = service_portal_prop['portalItems'] root_service = service.split('.')[0].replace('//', '/') for service_portal_item in service_portal_items: service_portal_ids['{}/{}'.format( root_service, service_portal_item['type'] )] = service_portal_item['itemID'].encode('ascii') return service_portal_ids
def get_service_portal_ids(server, port, user, password): service_portal_ids = None # Get list of services on specified ArcGIS Server service_list = getServiceList(server, port, user, password) if len(service_list) > 0: service_portal_ids = {} # Get ids for all portal items assocatied with each AGS service for service in service_list: parsed_service = service.split('//') folder = None if len(parsed_service) == 1: service_name_type = parsed_service[0] else: folder = parsed_service[0] service_name_type = parsed_service[1] service_portal_prop = getServicePortalProps(server, port, user, password, folder, service_name_type) service_portal_items = service_portal_prop['portalItems'] root_service = service.split('.')[0].replace('//', '/') for service_portal_item in service_portal_items: service_portal_ids['{}/{}'.format(root_service, service_portal_item['type'])] = service_portal_item['itemID'].encode('ascii') return service_portal_ids
def main(): totalSuccess = True # ------------------------------------------------- # Check arguments # ------------------------------------------------- results = check_args() if not results: sys.exit(exitErrCode) server, port, adminuser, password, use_ssl, output_file, owners = results if debug: print server, port, adminuser, password, use_ssl, output_file, owners if use_ssl: protocol = 'https' else: protocol = 'http' try: # Create connection to portal; need to get service item owner information portal = Portal('https://' + server + ':7443/arcgis', adminuser, password) # Verify if user specify owners exist invalid_owners = get_invalid_owners(portal, owners) if len(invalid_owners) > 0: print '\nThe following owners do not exist. Exiting script: \n{}'.format(', '.join(invalid_owners)) totalSuccess = False else: # Get all services that exist on server all_services = getServiceList(server, port, adminuser, password) all_services = [service.replace('//', '/') for service in all_services] # Create collection of only hosted services print '\n{}'.format('=' * 80) print 'Extracting service definition information (editing, sync, export, tracking)' print 'for hosted feature services that meet filter criteria.' print '{}\n'.format('=' * 80) definitions = {} for service in all_services: folder, serviceNameType = parseService(service) if serviceNameType.endswith('.FeatureServer'): portal_props = getServicePortalProps(server, port, adminuser, password, folder, serviceNameType) if portal_props: if portal_props['isHosted']: portal_items = portal_props['portalItems'] for portal_item in portal_items: #NOTE: for hosted services there should only be one portal item do_write = True item_id = portal_item['itemID'] item = portal.item(item_id) if item is None: print '\tPortal item {} for service does not exist.'.format(item_id) item_owner = None else: item_owner = item['owner'] if owners: if item_owner not in owners: do_write = False if do_write: print '{} ({})...'.format(service, item_owner) definition = getHostedServiceDefinition(server, port, adminuser, password, folder, serviceNameType) definitions[service] = {'owner': item_owner, 'updateDefinition': definition} # Write info to json file print '\nWriting "definition" information for {} services to file {}'.format(len(definitions), output_file) json.dump(definitions, open(output_file,'w')) print '\nDone.\n' except: totalSuccess = False # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) # Print Python error messages for use in Python / Python Window print print "***** ERROR ENCOUNTERED *****" print pymsg + "\n" finally: if totalSuccess: sys.exit(0) else: sys.exit(1)
def main(): totalSuccess = True # ------------------------------------------------- # Check arguments # ------------------------------------------------- results = check_args() if not results: sys.exit(exitErrCode) server, port, adminuser, password, use_ssl, output_file, owners = results if debug: print server, port, adminuser, password, use_ssl, output_file, owners if use_ssl: protocol = 'https' else: protocol = 'http' try: # Create connection to portal; need to get service item owner information portal = Portal('https://' + server + ':7443/arcgis', adminuser, password) # Verify if user specify owners exist invalid_owners = get_invalid_owners(portal, owners) if len(invalid_owners) > 0: print '\nThe following owners do not exist. Exiting script: \n{}'.format( ', '.join(invalid_owners)) totalSuccess = False else: # Get all services that exist on server all_services = getServiceList(server, port, adminuser, password) all_services = [ service.replace('//', '/') for service in all_services ] # Create collection of only hosted services print '\n{}'.format('=' * 80) print 'Extracting service definition information (editing, sync, export, tracking)' print 'for hosted feature services that meet filter criteria.' print '{}\n'.format('=' * 80) definitions = {} for service in all_services: folder, serviceNameType = parseService(service) if serviceNameType.endswith('.FeatureServer'): portal_props = getServicePortalProps( server, port, adminuser, password, folder, serviceNameType) if portal_props: if portal_props['isHosted']: portal_items = portal_props['portalItems'] for portal_item in portal_items: #NOTE: for hosted services there should only be one portal item do_write = True item_id = portal_item['itemID'] item = portal.item(item_id) if item is None: print '\tPortal item {} for service does not exist.'.format( item_id) item_owner = None else: item_owner = item['owner'] if owners: if item_owner not in owners: do_write = False if do_write: print '{} ({})...'.format( service, item_owner) definition = getHostedServiceDefinition( server, port, adminuser, password, folder, serviceNameType) definitions[service] = { 'owner': item_owner, 'updateDefinition': definition } # Write info to json file print '\nWriting "definition" information for {} services to file {}'.format( len(definitions), output_file) json.dump(definitions, open(output_file, 'w')) print '\nDone.\n' except: totalSuccess = False # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str( sys.exc_info()[1]) # Print Python error messages for use in Python / Python Window print print "***** ERROR ENCOUNTERED *****" print pymsg + "\n" finally: if totalSuccess: sys.exit(0) else: sys.exit(1)
def main(): totalSuccess = True # ------------------------------------------------- # Check arguments # ------------------------------------------------- results = check_args() if not results: sys.exit(exitErrCode) server, port, adminuser, password, use_ssl, output_folder, owners = results if debug: print server, port, adminuser, password, use_ssl, output_folder, owners if use_ssl: protocol = 'https' else: protocol = 'http' try: # Create connection to portal; need to get service item owner information portal = Portal('https://' + server + ':7443/arcgis', adminuser, password) # Verify if user specify owners exist invalid_owners = get_invalid_owners(portal, owners) if len(invalid_owners) > 0: print '\nThe following owners do not exist. Exiting script: \n{}'.format(', '.join(invalid_owners)) totalSuccess = False else: # Get all services that exist on server all_services = getServiceList(server, port, adminuser, password) all_services = [service.replace('//', '/') for service in all_services] # Create collection of only hosted services print '\n{}'.format('=' * 80) print 'Extracting scene service definition information for hosted scene services' print 'that meet criteria.' print '{}\n'.format('=' * 80) total_scene_services = 0 total_files_created = 0 for service in all_services: folder, serviceNameType = parseService(service) if serviceNameType.endswith('.SceneServer'): total_scene_services += 1 print '-' * 80 print 'Service: {}'.format(service) portal_props = getServicePortalProps(server, port, adminuser, password, folder, serviceNameType) if portal_props: if portal_props['isHosted']: portal_items = portal_props['portalItems'] for portal_item in portal_items: #NOTE: for hosted services there should only be one portal item do_write = True item_id = portal_item['itemID'] item = portal.item(item_id) if item is None: print '\tPortal item {} for service does not exist.'.format(item_id) item_owner = None else: item_owner = item['owner'] item_title = item['title'] print 'Item id: {}, Owner: {}, Title: {}'.format(item_id, item_owner, item_title) if owners: if item_owner not in owners: do_write = False if do_write: service_json = getServiceJSON(server, port, adminuser, password, folder, serviceNameType) definition = {} definition['name'] = serviceNameType.split('.')[0] definition['serviceDescription'] = service_json output_file = os.path.join(output_folder, serviceNameType.replace('.SceneServer', '') + '_sceneserver.json') # Write info to json file print '\nWriting "definition" to file {}'.format(output_file) json.dump(definition, open(output_file,'w')) total_files_created += 1 else: print 'Does not meet criteria. Will not write "definition" file.' print '-' * 80 print '\nTotal number of scene services: {}'.format(total_scene_services) print 'Total number of scene service definition files created: {}'.format(total_files_created) print '\nDone.\n' except: totalSuccess = False # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) # Print Python error messages for use in Python / Python Window print print "***** ERROR ENCOUNTERED *****" print pymsg + "\n" finally: if totalSuccess: sys.exit(0) else: sys.exit(1)
def main(): totalSuccess = True # ------------------------------------------------- # Check arguments # ------------------------------------------------- results = check_args() if not results: sys.exit(exitErrCode) server, port, adminuser, password, use_ssl, output_folder, owners = results if debug: print server, port, adminuser, password, use_ssl, output_folder, owners if use_ssl: protocol = 'https' else: protocol = 'http' try: # Create connection to portal; need to get service item owner information portal = Portal('https://' + server + ':7443/arcgis', adminuser, password) # Verify if user specify owners exist invalid_owners = get_invalid_owners(portal, owners) if len(invalid_owners) > 0: print '\nThe following owners do not exist. Exiting script: \n{}'.format( ', '.join(invalid_owners)) totalSuccess = False else: # Get all services that exist on server all_services = getServiceList(server, port, adminuser, password) all_services = [ service.replace('//', '/') for service in all_services ] # Create collection of only hosted services print '\n{}'.format('=' * 80) print 'Extracting scene service definition information for hosted scene services' print 'that meet criteria.' print '{}\n'.format('=' * 80) total_scene_services = 0 total_files_created = 0 for service in all_services: folder, serviceNameType = parseService(service) if serviceNameType.endswith('.SceneServer'): total_scene_services += 1 print '-' * 80 print 'Service: {}'.format(service) portal_props = getServicePortalProps( server, port, adminuser, password, folder, serviceNameType) if portal_props: if portal_props['isHosted']: portal_items = portal_props['portalItems'] for portal_item in portal_items: #NOTE: for hosted services there should only be one portal item do_write = True item_id = portal_item['itemID'] item = portal.item(item_id) if item is None: print '\tPortal item {} for service does not exist.'.format( item_id) item_owner = None else: item_owner = item['owner'] item_title = item['title'] print 'Item id: {}, Owner: {}, Title: {}'.format( item_id, item_owner, item_title) if owners: if item_owner not in owners: do_write = False if do_write: service_json = getServiceJSON( server, port, adminuser, password, folder, serviceNameType) definition = {} definition['name'] = serviceNameType.split( '.')[0] definition[ 'serviceDescription'] = service_json output_file = os.path.join( output_folder, serviceNameType.replace( '.SceneServer', '') + '_sceneserver.json') # Write info to json file print '\nWriting "definition" to file {}'.format( output_file) json.dump(definition, open(output_file, 'w')) total_files_created += 1 else: print 'Does not meet criteria. Will not write "definition" file.' print '-' * 80 print '\nTotal number of scene services: {}'.format( total_scene_services) print 'Total number of scene service definition files created: {}'.format( total_files_created) print '\nDone.\n' except: totalSuccess = False # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str( sys.exc_info()[1]) # Print Python error messages for use in Python / Python Window print print "***** ERROR ENCOUNTERED *****" print pymsg + "\n" finally: if totalSuccess: sys.exit(0) else: sys.exit(1)