def portal_info_plus(): portal = Portal('http://portaldev.esri.com') print portal.info() pprint(portal.properties()) pprint(portal.languages()) pprint(portal.regions()) pprint(portal.basemaps(['title'])) pprint(portal.color_sets(['title'])) pprint(portal.featured_items(['title'])) pprint(portal.featured_items_homepage(['title'])) pprint(portal.feature_collection_templates(['title'])) pprint(portal.symbol_sets(['title'])) pprint(portal.gallery_templates(['title'])) pprint(portal.webmap_templates(['title']))
def extract_portal(portaladdress, contentpath, adminuser, adminpassword, specifiedUsers): '''Extract Portal info and content for all specified users''' specifiedUsers = specifiedUsers.lower() excludeUsersList = [] includeUsersList = [] #if first character is a minus, then the "specifiedUsers" variable # contains a comma delimited string of the users to exclude from the extract if len(specifiedUsers) > 0: if specifiedUsers.find("-") == 0: specifiedUsers = specifiedUsers.replace("-", "", 1) excludeUsersList = specifiedUsers.split(",") else: includeUsersList = specifiedUsers.split(",") # Create root output folder if it doesn't exist. if not os.path.exists(contentpath): os.makedirs(contentpath) os.chdir(contentpath) #Make Admin connection to portal and retrieve portal info portaladmin = Portal(portaladdress, adminuser, adminpassword) # ------------------------------------------------------------------------ # Extract Portal Properties # ------------------------------------------------------------------------ portal_properties = portaladmin.properties() print "\n- Extracting portal info ..." json.dump(portal_properties, open('portal_properties.json', 'w')) #Get portal featured items # get a list of portal resources resources = portaladmin.resources(portal_properties['id']) json.dump(resources, open('resources.json', 'w')) # ------------------------------------------------------------------------ # Extract users, groups and items # ------------------------------------------------------------------------ print "\n- Extracting users, groups and items ..." usersList = [] usersListAllNames = [] # Get list of users on the source portal usersListAllNames_temp = portaladmin.users() # Remove any esri_ accounts from the list for u in usersListAllNames_temp: if not u["username"].startswith("esri_"): usersListAllNames.append(u) # Create list of users that we don't want to extract content for. # NOTE: specify user names in lowercase. userExcludeList = ["admin", "system_publisher", "administrator"] # If user has specified users to exclude from extract then add these # users to the exclude list if len(excludeUsersList) > 0: userExcludeList.extend(excludeUsersList) # Create output file to store username and fullname properties userfile = open(os.path.join(contentpath, 'userfile.txt'), 'w') # If only specific users should be extracted # then only keep those users in the user information dictionary if len(includeUsersList) > 0: for u in usersListAllNames: userName = u["username"] if userName.lower() in includeUsersList: usersList.append(u) else: usersList = usersListAllNames userfile.write("SourceUserName,TargetUserName,TargetPassword\n") for u in usersList: userName = u["username"] if userName.lower() not in userExcludeList: users[str(userName)] = None userfile.write(userName + "," + userName + ",MyDefault4Password!" + "\n") userfile.close() for username in users.keys(): # Create output folder if it doesn't exist extractpath = os.path.join(contentpath, username) if not os.path.exists(extractpath): os.makedirs(extractpath) print "\n" + sectionBreak print "Extracting content for user: " + username # Dump user info to json file userinfo = portaladmin.user(username) filepath = os.path.join(extractpath, 'userinfo.json') json.dump(userinfo, open(filepath, 'w')) # Extract folders for user extract_folders(portaladmin, extractpath, username) # Extract items owned by user extract_items(portaladmin, extractpath, username) # Extract groups owned by user extract_groups_from_user_info(portaladmin, userinfo, extractpath)
def extract_portal(portaladdress,contentpath,adminuser,adminpassword, specifiedUsers): '''Extract Portal info and content for all specified users''' specifiedUsers = specifiedUsers.lower() excludeUsersList = [] includeUsersList = [] #if first character is a minus, then the "specifiedUsers" variable # contains a comma delimited string of the users to exclude from the extract if len(specifiedUsers) > 0: if specifiedUsers.find("-") == 0: specifiedUsers = specifiedUsers.replace("-","",1) excludeUsersList = specifiedUsers.split(",") else: includeUsersList = specifiedUsers.split(",") # Create root output folder if it doesn't exist. if not os.path.exists(contentpath): os.makedirs(contentpath) os.chdir(contentpath) #Make Admin connection to portal and retrieve portal info portaladmin = Portal(portaladdress, adminuser, adminpassword) # ------------------------------------------------------------------------ # Extract Portal Properties # ------------------------------------------------------------------------ portal_properties = portaladmin.properties() print "\n- Extracting portal info ..." json.dump(portal_properties, open('portal_properties.json','w')) #Get portal featured items # get a list of portal resources resources = portaladmin.resources(portal_properties['id']) json.dump(resources,open('resources.json','w')) # ------------------------------------------------------------------------ # Extract users, groups and items # ------------------------------------------------------------------------ print "\n- Extracting users, groups and items ..." usersList = [] usersListAllNames = [] # Get list of users on the source portal usersListAllNames_temp = portaladmin.users() # Remove any esri_ accounts from the list for u in usersListAllNames_temp: if not u["username"].startswith("esri_"): usersListAllNames.append(u) # Create list of users that we don't want to extract content for. # NOTE: specify user names in lowercase. userExcludeList = ["admin", "system_publisher", "administrator"] # If user has specified users to exclude from extract then add these # users to the exclude list if len(excludeUsersList) > 0: userExcludeList.extend(excludeUsersList) # Create output file to store username and fullname properties userfile = open(os.path.join(contentpath,'userfile.txt'),'w') # If only specific users should be extracted # then only keep those users in the user information dictionary if len(includeUsersList) > 0: for u in usersListAllNames: userName = u["username"] if userName.lower() in includeUsersList: usersList.append(u) else: usersList = usersListAllNames userfile.write("SourceUserName,TargetUserName,TargetPassword\n") for u in usersList: userName = u["username"] if userName.lower() not in userExcludeList: users[str(userName)] = None userfile.write(userName + "," + userName + ",MyDefault4Password!" + "\n") userfile.close() for username in users.keys(): # Create output folder if it doesn't exist extractpath = os.path.join(contentpath, username) if not os.path.exists(extractpath): os.makedirs(extractpath) print "\n" + sectionBreak print "Extracting content for user: " + username # Dump user info to json file userinfo = portaladmin.user(username) filepath = os.path.join(extractpath, 'userinfo.json') json.dump(userinfo, open(filepath,'w')) # Extract folders for user extract_folders(portaladmin, extractpath, username) # Extract items owned by user extract_items(portaladmin, extractpath, username) # Extract groups owned by user extract_groups_from_user_info(portaladmin, userinfo, extractpath)
def publish_portal(portaladdress,contentpath,adminuser,adminpassword, users, hostname_map, specified_groups, id_mapping_file): os.chdir(contentpath) portal_properties = json.load(open("portal_properties.json")) portaladmin = Portal(portaladdress, adminuser, adminpassword) print_script_header(portaladmin, portal_processing, users, specified_groups) # Create Portal log folder for this portal portalLogPath = os.path.join(contentpath, portalLogFolder, get_servername_from_url(portaladmin.url)) makeFolder(portalLogPath) # ------------------------------------------------------------------------ # Get info about the groups on disk to filter items based on group membership # ------------------------------------------------------------------------ # Get the groups on disk grps_on_disk = get_groups_on_disk(contentpath) # Validate that each specified group is valid if specified_groups: invalid_specified_groups = [] for specified_group in specified_groups: found = False for grp in grps_on_disk.itervalues(): if specified_group == grp: found = True if not found: invalid_specified_groups.append(specified_group) if len(invalid_specified_groups) > 0: print '\n***ERROR: the following specified groups do not exist; NOTE: group owner and group title must match exactly including case:\n' print invalid_specified_groups return # ------------------------------------------------------------------------ # Create users # ------------------------------------------------------------------------ print titleBreak print 'Create users...\n' # Only create users if this is not an online organization if portaladmin.properties()['id'] == '0123456789ABCDEF': # All portals have this id. for username, userinfo in users.iteritems(): create_user(portaladmin, contentpath, userinfo) else: print '\tThis is an online organization. Users must already have been created.' # ------------------------------------------------------------------------ # Create user folders # ------------------------------------------------------------------------ print '\n'+ titleBreak print 'Create user folders...\n' for username, userinfo in users.iteritems(): print '\nUser: '******'target_username'] create_user_folders(portaladmin, contentpath, userinfo) # ------------------------------------------------------------------------ # Create groups and add users to groups # ------------------------------------------------------------------------ print "\n" + titleBreak print "Creating groups ...\n" oldGrpID_newGrpID = {} for username, userinfo in users.iteritems(): newGroups = publish_user_groups(portaladmin, contentpath, userinfo, users) for key,val in newGroups.iteritems(): oldGrpID_newGrpID[key] = {'id': val} # ------------------------------------------------------------------------ # Publish Items and Update their sharing info # ------------------------------------------------------------------------ print "\n" + titleBreak print "Publishing items and setting sharing ..." print titleBreak for username, userinfo in users.iteritems(): username = userinfo['target_username'] password = userinfo['target_password'] userfoldername = userinfo['username'] # --------------------------------------- # Publish all the users' items # --------------------------------------- usercontentpath = os.path.join(contentpath, userfoldername) newItems, origItemSourceIDs = publish_user_items(portaladmin, username, usercontentpath, source_hostname, new_hostname, new_port, specified_groups, id_mapping_file, grps_on_disk) # Dump info about new items to JSON to use for resetting IDs of related items dump_newItem_info(newItems, origItemSourceIDs, os.path.join(portalLogPath, username)) # --------------------------------------- # Share the users' items with the # appropriate groups # --------------------------------------- userItemsPath = os.path.join(contentpath, userfoldername, "items") share_items(portaladmin, userItemsPath, newItems, origItemSourceIDs, originGroupToDestGroups) # Dump info about all items (old, new ids) into json os.chdir(portalLogPath) json.dump(origIDToNewID, open('oldID_newID.json','w')) json.dump(oldGrpID_newGrpID, open('oldGrpID_newGrpID.json', 'w')) # ------------------------------------------------------------------------ # Post publishing processing: Update URLs and item ids # ------------------------------------------------------------------------ print "\n" + titleBreak print "Update URLs and Item IDs..." print titleBreak + "\n" # Add the group ids to the dictionary of old/new ids origIDToNewID.update(oldGrpID_newGrpID) # Create list of items to update # (exclude any items owned by esri_ accounts) items_all = portaladmin.search() items_to_update = [] for item in items_all: if not item["owner"].startswith("esri_"): items_to_update.append(item) # Update update_post_publish(portaladmin, hostname_map, origIDToNewID, items_to_update) # Comment out: this functionality is now available out of the box # # ------------------------------------------------------------------------ # # Share items in default web apps template and default gallery # # ------------------------------------------------------------------------ # # Share the items in the default web apps template and # # default gallery template built-in group with the # # 'OpsServer' user 'AFMI Web Application Templates' and # # 'AFMI Gallery Templates' # print "\n" + sectionBreak # print "Share the items in the default web apps and gallery template groups..." # group_owner = 'OpsServer' # if users.get(group_owner): # share_templates(portaladdress, users[group_owner]['target_username'], users[group_owner]['target_password']) # else: # print "-Skipping...user {} was not created. Can perform same operation through portal 'Edit Settings'.".format(group_owner) print "\nDONE: Finished posting content to portal."
def publish_portal(portaladdress, contentpath, adminuser, adminpassword, users, hostname_map, specified_groups, id_mapping_file): os.chdir(contentpath) portal_properties = json.load(open("portal_properties.json")) portaladmin = Portal(portaladdress, adminuser, adminpassword) print_script_header(portaladmin, portal_processing, users, specified_groups) # Create Portal log folder for this portal portalLogPath = os.path.join(contentpath, portalLogFolder, get_servername_from_url(portaladmin.url)) makeFolder(portalLogPath) # ------------------------------------------------------------------------ # Get info about the groups on disk to filter items based on group membership # ------------------------------------------------------------------------ # Get the groups on disk grps_on_disk = get_groups_on_disk(contentpath) # Validate that each specified group is valid if specified_groups: invalid_specified_groups = [] for specified_group in specified_groups: found = False for grp in grps_on_disk.itervalues(): if specified_group == grp: found = True if not found: invalid_specified_groups.append(specified_group) if len(invalid_specified_groups) > 0: print '\n***ERROR: the following specified groups do not exist; NOTE: group owner and group title must match exactly including case:\n' print invalid_specified_groups return # ------------------------------------------------------------------------ # Create users # ------------------------------------------------------------------------ print titleBreak print 'Create users...\n' # Only create users if this is not an online organization if portaladmin.properties( )['id'] == '0123456789ABCDEF': # All portals have this id. for username, userinfo in users.iteritems(): create_user(portaladmin, contentpath, userinfo) else: print '\tThis is an online organization. Users must already have been created.' # ------------------------------------------------------------------------ # Create user folders # ------------------------------------------------------------------------ print '\n' + titleBreak print 'Create user folders...\n' for username, userinfo in users.iteritems(): print '\nUser: '******'target_username'] create_user_folders(portaladmin, contentpath, userinfo) # ------------------------------------------------------------------------ # Create groups and add users to groups # ------------------------------------------------------------------------ print "\n" + titleBreak print "Creating groups ...\n" for username, userinfo in users.iteritems(): newGroups = publish_user_groups(portaladmin, contentpath, userinfo, users) # ------------------------------------------------------------------------ # Publish Items and Update their sharing info # ------------------------------------------------------------------------ print "\n" + titleBreak print "Publishing items and setting sharing ..." print titleBreak for username, userinfo in users.iteritems(): username = userinfo['target_username'] password = userinfo['target_password'] userfoldername = userinfo['username'] # --------------------------------------- # Publish all the users' items # --------------------------------------- usercontentpath = os.path.join(contentpath, userfoldername) newItems, origItemSourceIDs = publish_user_items( portaladmin, username, usercontentpath, source_hostname, new_hostname, new_port, specified_groups, id_mapping_file, grps_on_disk) # Dump info about new items to JSON to use for resetting IDs of related items dump_newItem_info(newItems, origItemSourceIDs, os.path.join(portalLogPath, username)) # --------------------------------------- # Share the users' items with the # appropriate groups # --------------------------------------- userItemsPath = os.path.join(contentpath, userfoldername, "items") share_items(portaladmin, userItemsPath, newItems, origItemSourceIDs, originGroupToDestGroups) # Dump info about all items (old, new ids) into json os.chdir(portalLogPath) json.dump(origIDToNewID, open('oldID_newID.json', 'w')) # ------------------------------------------------------------------------ # Post publishing processing: Update URLs and item ids # ------------------------------------------------------------------------ print "\n" + titleBreak print "Update URLs and Item IDs..." print titleBreak + "\n" update_post_publish(portaladmin, hostname_map, origIDToNewID) # ------------------------------------------------------------------------ # Share items in default web apps template and default gallery # ------------------------------------------------------------------------ # Share the items in the default web apps template and # default gallery template built-in group with the # 'OpsServer' user 'AFMI Web Application Templates' and # 'AFMI Gallery Templates' print "\n" + sectionBreak print "Share the items in the default web apps and gallery template groups..." share_templates(portaladdress, users['OpsServer']['target_username'], users['OpsServer']['target_password']) print "\nDONE: Finished posting content to portal."
def publish_portal(portaladdress, contentpath, adminuser, adminpassword, users, hostname_map, specified_groups, id_mapping_file): os.chdir(contentpath) portal_properties = json.load(open("portal_properties.json")) portaladmin = Portal(portaladdress, adminuser, adminpassword) print_script_header(portaladmin, portal_processing, users, specified_groups) # Create Portal log folder for this portal portalLogPath = os.path.join(contentpath, portalLogFolder, get_servername_from_url(portaladmin.url)) makeFolder(portalLogPath) # ------------------------------------------------------------------------ # Get info about the groups on disk to filter items based on group membership # ------------------------------------------------------------------------ # Get the groups on disk grps_on_disk = get_groups_on_disk(contentpath) # Validate that each specified group is valid if specified_groups: invalid_specified_groups = [] for specified_group in specified_groups: found = False for grp in grps_on_disk.itervalues(): if specified_group == grp: found = True if not found: invalid_specified_groups.append(specified_group) if len(invalid_specified_groups) > 0: print '\n***ERROR: the following specified groups do not exist; NOTE: group owner and group title must match exactly including case:\n' print invalid_specified_groups return # ------------------------------------------------------------------------ # Create users # ------------------------------------------------------------------------ print titleBreak print 'Create users...\n' # Only create users if this is not an online organization if portaladmin.properties( )['id'] == '0123456789ABCDEF': # All portals have this id. for username, userinfo in users.iteritems(): create_user(portaladmin, contentpath, userinfo) else: print '\tThis is an online organization. Users must already have been created.' # ------------------------------------------------------------------------ # Create user folders # ------------------------------------------------------------------------ print '\n' + titleBreak print 'Create user folders...\n' for username, userinfo in users.iteritems(): print '\nUser: '******'target_username'] create_user_folders(portaladmin, contentpath, userinfo) # ------------------------------------------------------------------------ # Create groups and add users to groups # ------------------------------------------------------------------------ print "\n" + titleBreak print "Creating groups ...\n" oldGrpID_newGrpID = {} for username, userinfo in users.iteritems(): newGroups = publish_user_groups(portaladmin, contentpath, userinfo, users) for key, val in newGroups.iteritems(): oldGrpID_newGrpID[key] = {'id': val} # ------------------------------------------------------------------------ # Publish Items and Update their sharing info # ------------------------------------------------------------------------ print "\n" + titleBreak print "Publishing items and setting sharing ..." print titleBreak for username, userinfo in users.iteritems(): username = userinfo['target_username'] password = userinfo['target_password'] userfoldername = userinfo['username'] # --------------------------------------- # Publish all the users' items # --------------------------------------- usercontentpath = os.path.join(contentpath, userfoldername) newItems, origItemSourceIDs = publish_user_items( portaladmin, username, usercontentpath, source_hostname, new_hostname, new_port, specified_groups, id_mapping_file, grps_on_disk) # Dump info about new items to JSON to use for resetting IDs of related items dump_newItem_info(newItems, origItemSourceIDs, os.path.join(portalLogPath, username)) # --------------------------------------- # Share the users' items with the # appropriate groups # --------------------------------------- userItemsPath = os.path.join(contentpath, userfoldername, "items") share_items(portaladmin, userItemsPath, newItems, origItemSourceIDs, originGroupToDestGroups) # Dump info about all items (old, new ids) into json os.chdir(portalLogPath) json.dump(origIDToNewID, open('oldID_newID.json', 'w')) json.dump(oldGrpID_newGrpID, open('oldGrpID_newGrpID.json', 'w')) # ------------------------------------------------------------------------ # Post publishing processing: Update URLs and item ids # ------------------------------------------------------------------------ print "\n" + titleBreak print "Update URLs and Item IDs..." print titleBreak + "\n" # Add the group ids to the dictionary of old/new ids origIDToNewID.update(oldGrpID_newGrpID) # Create list of items to update # (exclude any items owned by esri_ accounts) items_all = portaladmin.search() items_to_update = [] for item in items_all: if not item["owner"].startswith("esri_"): items_to_update.append(item) # Update update_post_publish(portaladmin, hostname_map, origIDToNewID, items_to_update) # Comment out: this functionality is now available out of the box # # ------------------------------------------------------------------------ # # Share items in default web apps template and default gallery # # ------------------------------------------------------------------------ # # Share the items in the default web apps template and # # default gallery template built-in group with the # # 'OpsServer' user 'AFMI Web Application Templates' and # # 'AFMI Gallery Templates' # print "\n" + sectionBreak # print "Share the items in the default web apps and gallery template groups..." # group_owner = 'OpsServer' # if users.get(group_owner): # share_templates(portaladdress, users[group_owner]['target_username'], users[group_owner]['target_password']) # else: # print "-Skipping...user {} was not created. Can perform same operation through portal 'Edit Settings'.".format(group_owner) print "\nDONE: Finished posting content to portal."