当前位置: 首页>>代码示例>>Python>>正文


Python Portal.users方法代码示例

本文整理汇总了Python中portalpy.Portal.users方法的典型用法代码示例。如果您正苦于以下问题:Python Portal.users方法的具体用法?Python Portal.users怎么用?Python Portal.users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在portalpy.Portal的用法示例。


在下文中一共展示了Portal.users方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: extract_portal

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import users [as 别名]
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
#.........这里部分代码省略.........
开发者ID:Esri,项目名称:ops-server-config,代码行数:103,代码来源:PortalContentExtract.py

示例2: main

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import users [as 别名]
def main():
    
    scriptName = sys.argv[0]
    
    # ---------------------------------------------------------------------
    # Check arguments
    # ---------------------------------------------------------------------   
    if len(sys.argv) <> 4:
        print '\n' + scriptName + ' <PortalURL> <AdminUser> <AdminPassword>'

        print '\nWhere:'
        print '\n\t<PortalURL> (required parameter): URL of Portal to delete content (i.e. https://fully_qualified_domain_name/arcgis)'
        print '\n\t<AdminUser> (required parameter): Portal user that has administrator role.'
        print '\n\t<AdminPassword> (required parameter): Password for AdminUser.\n'
        sys.exit(1)
    
    # Set variables from script parameters
    portal_address = sys.argv[1]
    adminuser = sys.argv[2]
    adminpassword = sys.argv[3]

    # Add specified user parameter value to exclude list.
    if adminuser not in exclude_users:
        exclude_users.append(adminuser)
            
    # Create portal object based on specified connection information
    portaladmin = Portal(portal_address, adminuser, adminpassword)
    portalProps = portaladmin.properties
    
    print sectionBreak
    print "Deleting Portal Content"
    print sectionBreak
    print "Portal: " + portaladmin.hostname
    print "Excluded users: " + str(exclude_users)
    print
    
    print "WARNING: this script will delete all user content in the specified portal: "
    print portaladmin.url + "\n"
    user_response = raw_input("Do you want to continue? Enter 'y' to continue: ")
    
    if not val_user_response(user_response):
        print "Exiting script..."
        sys.exit(1)
    
    # get a list of users
    portal_users = portaladmin.users()
    
    # Create list of users to delete
    portal_users_to_del = []
    for portal_user in portal_users:
        if portal_user['username'] not in exclude_users:
            portal_users_to_del.append(portal_user)    
    
    if len(portal_users_to_del) == 0:
        print "\nWARNING: there are no users to delete. Exiting script."
        sys.exit(1)
    
    # remove their groups and items
    for user_dict in portal_users_to_del:
        current_user = user_dict['username']
        
        print sectionBreak
        print "User: \t" + current_user
        
        # Delete the user and all owned groups and content
        resp = portaladmin.delete_user(current_user, cascade=True)
        printResponse(resp)
            
    print "\nDONE: Finished deleting content from portal."
开发者ID:ACueva,项目名称:ops-server-config,代码行数:71,代码来源:PortalContentDestroyer.py


注:本文中的portalpy.Portal.users方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。