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


Python Portal.org_users方法代码示例

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


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

示例1: create_user_group_item_reports

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import org_users [as 别名]
def create_user_group_item_reports():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    item_fields = ['id', 'title', 'owner', 'numViews']
    items = portal.search(item_fields, sort_field='numViews', sort_order='desc')
    csvfile = csv.writer(open('items-report.csv', 'wb'))
    csvfile.writerow(item_fields)
    for item in items:
        row = [item[field] for field in item_fields]
        csvfile.writerow(row)

    groups_fields = ['id', 'title', 'owner']
    groups = portal.groups(groups_fields)
    csvfile = csv.writer(open('groups-report.csv', 'wb'))
    csvfile.writerow(groups_fields)
    for group in groups:
        row = [group[field] for field in groups_fields]
        csvfile.writerow(row)

    user_fields = ['username', 'fullName', 'email', 'role']
    users = portal.org_users(user_fields)
    csvfile = csv.writer(open('users-report.csv', 'wb'))
    csvfile.writerow(user_fields)
    for user in users:
        row = [user[field] for field in user_fields]
        csvfile.writerow(row)
开发者ID:VandanaR,项目名称:PortalPy-AddIn,代码行数:28,代码来源:recipes.py

示例2: main

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import org_users [as 别名]
def main():
    
    totalSuccess = True
    out_file = None
    
    # Check arguments
    results = check_args()
    if not results:
        sys.exit(exitErrCode)
    
    # Get parameter values
    portal_url, user, password, output_file, output_per_user = results
    
    try:
        access_mode = 'w'
        
        # Create portal object
        portal = Portal(portal_url, user, password)
        
        if not portal:
            raise Exception('ERROR: Could not create "portal" object.')
        
        if not portal.logged_in_user():
            raise Exception('\nERROR: Could not sign in with specified credentials.')
        
        # Get portal users
        portal_users = portal.org_users()
        
        out_file = open(output_file, access_mode)
        out_file_dir = os.path.dirname(output_file)
        
        for portal_user in portal_users:
            
            user_name = portal_user['username']
            
            if user_name in username_exclude:
                continue
            
            if output_per_user:
                service_list_outfile = os.path.join(out_file_dir, '{}_ServiceList.txt'.format(user_name))
                service_list_qc_outfile = os.path.join(out_file_dir, '{}_CreateServiceList_output.txt'.format(user_name))
                access_mode = 'OVERWRITE'
                redirect = '>'
            else:
                service_list_outfile = os.path.join(out_file_dir, 'ServiceList.txt')
                service_list_qc_outfile = os.path.join(out_file_dir, 'CreateServiceList_output.txt')
                access_mode = 'APPEND'
                redirect = '>>'
                
            script_parameters = '{} {} {} {} {} {} {} {} {}'.format(
                    os.path.join(script_path, 'CreateServiceList.py'),
                    portal_url, user, password, service_list_outfile,
                    access_mode, user_name, redirect, service_list_qc_outfile)
            
            out_file.write(script_parameters + '\n')
        
        print '\nCreated output batch file: {}\n'.format(output_file)
        print 'Done.'
        
    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 hasattr(out_file, 'close'):
            out_file.close()
        if totalSuccess:
            sys.exit(0)
        else:
            sys.exit(1)
开发者ID:Esri,项目名称:ops-server-config,代码行数:83,代码来源:CreateBatchFileToRunCreateServiceList.py

示例3: delete_non_admin_users

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import org_users [as 别名]
def delete_non_admin_users():
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    users = portal.org_users(['username', 'role'])
    for user in users:
        if user['role'] != 'org_admin':
            portal.delete_user(user['username'], cascade=True)
开发者ID:VandanaR,项目名称:PortalPy-AddIn,代码行数:8,代码来源:recipes.py

示例4: count_user_roles

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import org_users [as 别名]
def count_user_roles():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    results = portal.org_users(['role', 'count(role)'], group_fields=['role'])
    pprint(results, indent=2)
开发者ID:VandanaR,项目名称:PortalPy-AddIn,代码行数:6,代码来源:recipes.py

示例5: main

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import org_users [as 别名]
def main():
    output_root = None
    
    # Get script parameters
    results = check_args()
    if not results:
        sys.exit(0)
    portal_address, adminuser, password, src_ids = results
        
    try:        
        
        # Create portal connection object
        portal = Portal(portal_address, adminuser, password)
        
        # Check if any specified GUIDs do not exist
        invalid_guids = validate_guids(portal, src_ids)
        if len(invalid_guids) > 0:
            raise Exception(
                'ERROR: The following portal items do not exist: {}'.format(
                                                            invalid_guids))
        
        # Create list of users
        users = [org_user['username'] for org_user in portal.org_users()]
        target_users = [user for user in users if user not in exclude_users]
        
        # -----------------------------------------------------------------
        # Extract portal items
        # -----------------------------------------------------------------
        print '\n\n{}\nExtracting select portal items...\n{}\n'.format(
                                    sec_char * sec_len, sec_char * sec_len)
        
        # Create temporary extract folder in OS users' temp directory
        output_root = os.path.join(tempfile.gettempdir(), 
                                    os.path.basename(
                                    sys.argv[0]).split('.')[0] + '_Extract' )
        os.makedirs(output_root)
        
        print 'Extract folder: {}'.format(output_root)
        
        # Extract specified portal item(s)
        for src_id in src_ids:
            src_item = portal.item(src_id)
            os.chdir(output_root)
            print '- Extracting item {} "{}" ({}) user account {}...'.format(
                                    src_item['id'], src_item['title'],
                                    src_item['type'], src_item['owner'])
            PortalContentExtract.extract_item(
                                    portal, src_item['id'], 
                                    src_item['owner'])
        
        # Create list of paths to individual extracted portal item folders
        src_item_paths = [os.path.join(output_root, 
                                        src_id) for src_id in src_ids]
        
        # -----------------------------------------------------------------
        # Publish extracted portal items for each user
        # -----------------------------------------------------------------
        print '\n\n{}\nPublish extracted items to each portal' \
                    'user account...\n{}'.format(sec_char * sec_len,
                                                 sec_char * sec_len)
        print 'NOTE: not publishing to the following users:'
        print exclude_users
        
        for target_user in target_users:
            print '\n\nUser Account: {}'.format(target_user)
            
            # Get info about user folders
            target_user_folders = portal.folders(target_user)
            
            for src_item_path in src_item_paths:
                
                # Get info about the source item
                os.chdir(src_item_path)
                src_item_json = json.load(open('item.json'))
                item_title = src_item_json['title']
                item_type = src_item_json['type']
                item_id = src_item_json['id']
                item_owner = src_item_json['owner']
                item_folder_id = src_item_json['ownerFolder']
                
                # Create folder in user account for item
                item_folder_name = get_folder_name(portal, item_owner,
                                                   item_folder_id)
                if item_folder_name:
                    if not has_folder(portal, target_user, item_folder_name):
                        print 'Creating target folder "{}" in account ' \
                                '{}...'.format(item_folder_name, target_user)
                        portal.create_folder(target_user, item_folder_name)
                
                # Check if user already owns item
                user_items = portal.search(
                                q='owner:{} AND type:{} AND title:{}'.format(
                                target_user, item_type, item_title))
                
                # Add item if item does not exist in user account or 
                # update item if it already exists
                if len(user_items) == 0:
                    print '\n- Add item "{}" ({}) to user account {}...'.format(
                                        item_title, item_type,
                                        portal.logged_in_user()['username'])
#.........这里部分代码省略.........
开发者ID:Esri,项目名称:ops-server-config,代码行数:103,代码来源:CopyItemToEachAccount.py


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