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


Python Portal.reassign_item方法代码示例

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


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

示例1: main

# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import reassign_item [as 别名]

#.........这里部分代码省略.........
        # -----------------------------------------------------------------
        # 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'])
                    item, orig_id = provision.load_item(portal, src_item_path)
                    
                    print '- Reassign item to user account {}, ' \
                                'folder "{}"...'.format(target_user,
                                                        item_folder_name)
                    portal.reassign_item(item.get('id'), target_user, item_folder_name)
                else:
                    for user_item in user_items:
                        if user_item['id'] <> item_id:
                            print '\n- Update existing item {} ' \
                                    '"{}" ({}) user account {}...'.format(
                                            user_item['id'], user_item['title'],
                                            user_item['type'], user_item['owner'])
                            item, orig_id = provision.load_item(
                                            portal, src_item_path, 
                                            user_item['id'])
                            
                            print '- Reassign item to user account {}, ' \
                                'folder "{}"...'.format(target_user,
                                                        item_folder_name)
                            portal.reassign_item(item.get('id'), target_user, item_folder_name)
                            
                        else:
                            print '*** No need to update item {}; ' \
                                    'user is owner of extracted item.'.format(
                                    user_item['id'])
        print '\n\nDone.'
        
    except:
        
        # 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:
        
        # Change directory to starting directory, otherwise the
        # delete will fail.
        os.chdir(start_dir)
        
        # Delete temp extracted folder/files
        if output_root:
            if os.path.exists(output_root):
                shutil.rmtree(output_root)
开发者ID:Esri,项目名称:ops-server-config,代码行数:104,代码来源:CopyItemToEachAccount.py


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