本文整理汇总了Python中portalpy.Portal.folders方法的典型用法代码示例。如果您正苦于以下问题:Python Portal.folders方法的具体用法?Python Portal.folders怎么用?Python Portal.folders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类portalpy.Portal
的用法示例。
在下文中一共展示了Portal.folders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import folders [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'])
#.........这里部分代码省略.........