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


Python Portal.resources方法代码示例

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


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

示例1: extract_portal

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import resources [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


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