本文整理汇总了Python中portalpy.Portal.logged_in_user方法的典型用法代码示例。如果您正苦于以下问题:Python Portal.logged_in_user方法的具体用法?Python Portal.logged_in_user怎么用?Python Portal.logged_in_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类portalpy.Portal
的用法示例。
在下文中一共展示了Portal.logged_in_user方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_user_with_groups_and_items
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
def copy_user_with_groups_and_items():
source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
target = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
source_owner = source.logged_in_user()['username']
target_owner = target.logged_in_user()['username']
# Copy the groups
groups = source.groups(q='owner:' + source_owner)
copied_groups = copy_groups(groups, source, target)
print 'Copied ' + str(len(copied_groups)) + ' groups'
# Copy the items
copied_items = copy_user_contents(source, source_owner, target, target_owner)
print 'Copied ' + str(len(copied_items)) + ' items'
# Share the items in the target portal
for item_id in copied_items.keys():
sharing = source.user_item(item_id)[1]
if sharing['access'] != 'private':
target_item_id = copied_items[item_id]
target_group_ids = [copied_groups[id] for id in sharing['groups']\
if id in copied_groups]
target.share_items(target_owner, [target_item_id], target_group_ids,\
sharing['access'] == 'org',\
sharing['access'] == 'public')
示例2: share_templates
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
def share_templates(portaladdress, username, password):
# Create portal connection
portal = Portal(portaladdress, username, password)
print '\nShare web app templates with "AFMI Web Application Templates" group...'
results = share_default_webapp_templates(portal, portal.logged_in_user()['username'], 'AFMI Web Application Templates')
if results['success']:
print '\tDone.'
else:
print 'ERROR: {}'.format(results['message'])
print '\nShare web app templates with "AFMI Gallery Templates" group...'
results = share_default_gallery_templates(portal, portal.logged_in_user()['username'], 'AFMI Gallery Templates')
if results['success']:
print '\tDone.'
else:
print 'ERROR: {}'.format(results['message'])
示例3: create_demographics_group
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
def create_demographics_group():
arcgisonline = Portal('http://www.arcgis.com')
portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
owner = portal.logged_in_user()['username']
items = arcgisonline.search(q='demographics owner:esri ' + WEBMAP_ITEM_FILTER)
copied_items = copy_items(items, arcgisonline, portal, owner)
group_id = portal.create_group({'title': 'Demographics', 'access': 'public',
'tags': 'demographics'},
thumbnail='http://bit.ly/WEaIh5')
for item_id in copied_items.values():
portal.share_items(owner, [item_id], [group_id], True, True)
示例4: copy_group_with_shared_content
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
def copy_group_with_shared_content():
source = Portal('http://www.arcgis.com')
target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
target_owner = target.logged_in_user()['username']
group_id = '2394b887a80347fb8544610cfa30489c'
# Copy the groups
groups = source.groups(q='id:' + group_id)
copied_groups = copy_groups(groups, source, target)
print 'Copied ' + str(len(copied_groups)) + ' groups'
# Copy the items
items = source.search(q='group:' + group_id)
copied_items = copy_items(items, source, target, target_owner,
'Copied Items (' + group_id + ')')
print 'Copied ' + str(len(copied_items)) + ' items'
# Share the items in the target portal
for item_id in copied_items.keys():
sharing = source.user_item(item_id)[1]
# If we have access to the full sharing properties of the source
# item, then copy all of them, otherwise just share with the group
if sharing and sharing['access'] != 'private':
target_item_id = copied_items[item_id]
target_group_ids = [copied_groups[id] for id in sharing['groups'] \
if id in copied_groups]
share_org = (sharing['access'] == 'org')
share_public = (sharing['access'] == 'public')
if not target.is_multitenant():
share_public = (share_public or share_org)
target.share_items(target_owner, [target_item_id],
target_group_ids, \
share_org or share_public, \
share_public)
else:
target_item_id = copied_items[item_id]
target_group_id = copied_groups[group_id]
target.share_items(target_owner, [target_item_id], \
[target_group_id])
示例5: copy_users
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
def copy_users():
source = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
owners = ['admin', 'wmathot']
target_owner = target.logged_in_user()['username']
for owner in owners:
groups = source.groups(q='owner:' + owner)
copied_groups = copy_groups(groups, source, target, target_owner)
copied_items = copy_user_contents(source, owner, target, target_owner)
for item_id in copied_items.keys():
sharing = source.user_item(item_id)[1]
if sharing['access'] != 'private':
target_item_id = copied_items[item_id]
target_group_ids = [copied_groups[id] for id in sharing['groups']\
if id in copied_groups]
share_org = (sharing['access'] == 'org')
share_public = (sharing['access'] == 'public')
if not target.is_multitenant():
share_public = (share_public or share_org)
target.share_items(target_owner, [target_item_id],
target_group_ids,\
share_org or share_public,\
share_public)
示例6: main
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [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)
示例7: Portal
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
feature_items, feature_groups
from portalpy.provision import load_groups, copy_items
logging.basicConfig(level=logging.WARN)
# Setup portal connections and file paths
portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
arcgisonline = Portal('http://www.arcgis.com')
groups_csv = '.\\provision_groups.csv'
# Configure the portal
configure_portal(portal, 'Demo Portal', 'A portal used for demonstrations.')
create_basemap_gallery_group(portal, 'Demo Basemaps', copy_filter='-bing -osm')
# Create groups from CSV, then copy/share like-tagged items from arcgis online
items_to_feature = []
owner = portal.logged_in_user()['username']
groups = load_groups(portal, groups_csv, 'csv')[0]
for group in groups:
tags = group['tags'].split(',')
tags_expr = ' OR '.join('tags:"%s"' % tag.strip() for tag in tags)
item_query = WEB_ITEM_FILTER + ' AND (' + tags_expr + ')'
items = arcgisonline.search(q=item_query, num=5)
item_id_map = copy_items(items, arcgisonline, portal, owner)
portal.share_items(owner, item_id_map.values(), [group['id']], True, True)
items_to_feature.append(item_id_map[items[0]['id']])
# Feature items and groups (clear_existing=True)
feature_items(portal, items_to_feature, True)
feature_groups(portal, random.sample(groups, 5), True)
示例8: main
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [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'])
#.........这里部分代码省略.........
示例9: main
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [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, access_mode, owner, group = results
global portal_netloc
portal_netloc = urlparse.urlparse(portal_url).netloc
try:
# 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 items
items = searchPortal(portal, owner, group)
# Get portal item ids for all AGS services
urlparts = urlparse.urlparse(portal_url)
server = urlparts.hostname
# NOTE: call to following function assumes AGS server is using
# same username and password as portal
service_portal_ids = get_service_portal_ids(server, 6443, user, password)
all_urls = []
services = []
type_mapping = {'FeatureServer':'MapServer', 'NAServer':'MapServer',
'MobileServer':'MapServer', 'SchematicsServer':'MapServer'}
if items:
for item in items:
# if item['id'] <> 'faef542a74e141398c05c43379a67004':
# continue
print '-' * 200
if 'Service' in item.get('typeKeywords'):
if not 'Service Definition' in item.get('typeKeywords'):
print_item_info2(item)
url = item.get('url')
all_urls.append(url)
p_item_id = _get_item_id(url, service_portal_ids)
print '\n\t\t{:<14}{:<32} {:<115}{:<25}'.format('Service', str(p_item_id), str(_get_item_title(portal, p_item_id)), str(_get_item_owner(portal, p_item_id)))
print '\t\t{:<14}{:>32} {:<115}'.format('','URL:',url)
if do_url_checks:
_check_url(url)
elif item.get('type') == 'Web Map':
print_item_info2(item)
urls = get_webmap_service_urls(portal, item)
for url in urls:
all_urls.append(url)
p_item_id = _get_item_id(url, service_portal_ids)
print '\n\t\t{:<14}{:<32} {:<115}{:<25}'.format('Service', str(p_item_id), str(_get_item_title(portal, p_item_id)), str(_get_item_owner(portal, p_item_id)))
print '\t\t{:<14}{:>32} {:<115}'.format('','URL:',url)
if do_url_checks:
_check_url(url)
elif item.get('type') == 'Operation View':
print_item_info2(item)
urls = get_opview_service_urls(portal, item, service_portal_ids)
for url in urls:
all_urls.append(url)
elif item.get('type') == 'Web Mapping Application':
print_item_info2(item)
if 'Story Map' in item.get('typeKeywords'):
print '(Story Map)'
urls = get_storymap_resources(portal, item, service_portal_ids)
for url in urls:
all_urls.append(url)
else:
urls = get_webapp_service_urls(portal, item, service_portal_ids)
for url in urls:
all_urls.append(url)
else:
print_item_info2(item)
print '\tSkipping service search for this item type...'
if all_urls:
for url in all_urls:
#.........这里部分代码省略.........
示例10: main
# 需要导入模块: from portalpy import Portal [as 别名]
# 或者: from portalpy.Portal import logged_in_user [as 别名]
#.........这里部分代码省略.........
continue
if servicePortalItems:
print '\n\t- Associated portal items...'
for servicePortalItem in servicePortalItems:
orig_id = servicePortalItem['itemID']
# Get service search string
serviceSearchStr = getServiceSearchString(service, servicePortalItem)
print '\n\t - ' + serviceSearchStr + ': original item id = ' + orig_id
# Get new portal item id
new_id = findPortalItemID(server, serviceSearchStr, portal_url_items)
if new_id:
if (new_id <> orig_id):
numIDsFoundForService = numIDsFoundForService + 1
servicePortalItem['itemID'] = new_id
portalItemIDsToDelete.append(orig_id)
print '\t\tFound new item id - ' + new_id
else:
print '\t\tItem IDs match, not processing.'
else:
print '\n\t**** WARNING: new item id not found.'
servicePortalProps['portalItems'] = servicePortalItems
info['portalProperties'] = servicePortalProps
if doUpdateService:
print '\n\n\t- Updating portal item information stored within service JSON (service will be restarted automatically)...'
if numIDsFoundForService == 0:
print '\n\t**** WARNING: there were no new ids found for this service so there is no need to update the service JSON info.'
continue
success, status = editServiceInfo(server, port, adminuser, password, folder, serviceNameType, info)
if success:
print '\t\tDone.'
else:
totalSuccess = False
print '**** ERROR: Update of service was not successful.'
print 'status: ' + str(status)
if doDeleteItems:
print
#print '=' * 100
print '\n\n-Deleting portal items that were remapped to original portal item...'
if len(portalItemIDsToDelete) == 0:
print '\n**** ERROR: No portal items to delete; which means there were no portal items '
print '\t owned by ' + portal.logged_in_user()['username'] + ' that were remapped to original portal item.\n'
# Get list of all portal ids so we can verify that the portal item exists before we delete
portal_items = portal.search(['id'])
time.sleep(5)
for portalItemID in portalItemIDsToDelete:
time.sleep(2)
itemFound = False
print ' -Deleting id ' + portalItemID + '...'
# Delete if item exists
for portal_item in portal_items:
if portal_item['id'] == portalItemID:
itemFound = True
results = portal.delete_item(portalItemID, portal.logged_in_user()['username'])
if results:
print '\tDone.'
else:
totalSuccess = False
print '**** ERROR: Deletion of service was not successful.'
if not itemFound:
print '\tItem ' + portalItemID + ' does not exist. Skipping...'
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:
print
print
if totalSuccess:
print "Remap of portal item ids on services was completed successfully."
sys.exit(0)
else:
print "ERROR: Remap of portal item ids on services was _NOT_ completed successfully."
sys.exit(1)