操作方法
在某些情况下,需要确定 Portal for ArcGIS 项目之间的依赖关系。 例如,在数据清理过程中,可能需要删除 web 应用程序及其关联的 web 地图。 手动检查这些依赖项可能有些枯燥乏味。 另外,可使用以下 ArcGIS API for Python 函数以管理员权限以编程方式执行此过程:dependent_upon() 和dependent_to()。
以下步骤描述了如何使用 ArcGIS API for Python 在 Portal for ArcGIS 中查找依赖项。
from arcgis.gis import GIS from IPython.display import display
source = GIS("<portalurl>", "<admin_user>", "<admin_password>") source_users = source.users.search(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False, exclude_system=True) source_items_by_id = {} print('User list: Role')
for user in source_users: print(user.username + "\t:\t" + str(user.role))
for user in source_users: num_items = 0 num_folders = 0 print("Collecting item ids for {}".format(user.username), end="\n\n") user_content = user.items()
for item in user_content: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to()))
folders = user.folders for folder in folders: num_folders += 1 folder_items = user.items(folder=folder['title']) for item in folder_items: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) print("Number of folders {} # Number of items {} # Number of users {}".format(str(num_folders), str(num_items), len(source_users)))
以下显示了完整脚本:
from arcgis.gis import GIS from IPython.display import display source = GIS("https://test.domain.com/portal", "portaladmin", "portaladmin") source_users = source.users.search(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False, exclude_system=True) source_items_by_id = {} print('User list: Role') for user in source_users: print(user.username + "\t:\t" + str(user.role)) for user in source_users: num_items = 0 num_folders = 0 print("Collecting item ids for {}".format(user.username), end="\n\n") user_content = user.items() for item in user_content: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) folders = user.folders for folder in folders: num_folders += 1 folder_items = user.items(folder=folder['title']) for item in folder_items: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) print("Number of folders {} # Number of items {} # Number of users {}".format(str(num_folders), str(num_items), len(source_users)))
获取来自 ArcGIS 专家的帮助
下载 Esri 支持应用程序