本文整理汇总了Python中portalpy.Portal.user方法的典型用法代码示例。如果您正苦于以下问题:Python Portal.user方法的具体用法?Python Portal.user怎么用?Python Portal.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类portalpy.Portal
的用法示例。
在下文中一共展示了Portal.user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_public_content_with_weak_descriptions
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import user [as 别名]
def find_public_content_with_weak_descriptions():
portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
public_items = portal.search(q='access:public')
weak_items = []
for item in public_items:
snippet = item.get('snippet')
description = item.get('description')
thumbnail = item.get('thumbnail')
if not snippet or not description or not thumbnail or len(snippet) < 20 \
or len(description) < 50:
weak_items.append(item)
for weak_item in weak_items:
owner = weak_item['owner']
email = portal.user(owner)['email']
print owner + ', ' + email + ', ' + weak_item['id']
示例2: extract_portal
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import user [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
#.........这里部分代码省略.........