22import datetime
33
44"""accounts to keep from user/groups/items deletion"""
5- ignore_accounts = ['andrew' , 'andrew.chapkowski' , 'dvitale' , 'david.vitale' ,
5+ ignore_accounts_online = ['DavidJVitale' , 'yjiang_geosaurus' , 'amani_geosaurus' , 'api_data_owner' ,
6+ 'bmajor_geosaurus' , 'rsingh_geosaurus' , 'rohitgeo' , 'andrew887' ,
7+ 'cwhitmore_geosaurus' , 'ArcGISPyAPIBot' , 'jyaist_geosaurus' , 'cpeng_geosaurus' ]
8+
9+ ignore_accounts_playground = ['andrew' , 'andrew.chapkowski' , 'dvitale' , 'david.vitale' ,
610 'atma.mani' , 'john.yaist' , 'bill.major' , 'YJiang' ,
711 'rohit.singh' , 'rohitgeo' , 'gbochenek_python' ,
812 'system_publisher' , 'admin' , 'portaladmin' ,
913 'Demo_User' , 'First_User' , 'Second_User' ,
1014 'api_data_owner' , 'arcgis_python' , 'temp_execution' ]
1115
1216"""accounts that you want to delete groups and items, but keep user"""
13- target_accounts = ['arcgis_python' ]
17+ target_accounts_online = ['arcgis_python' ]
18+ target_accounts_playground = ['arcgis_python' ]
1419
15- """create GIS connection via admin credentials"""
16- # gis = GIS(profile='your_entp_admin_profile', verify_cert=False)
17- gis = GIS ("https://pythonapi.playground.esri.com/portal" ,"temp_execution" , "temp_execution123" )
20+ """data to publish"""
21+ data_paths = [r'\\archive\crdata\Geosaurus_datasets\data_prep\csv\Trailheads.csv' ]
1822
23+ """create GIS connection via admin credentials"""
24+ gis_online = GIS (profile = "your_online_admin_profile" )
25+ gis_playground = GIS (profile = 'your_ent_admin_profile' )
1926
2027def delete_depending_items (dependent_item ):
2128 """deletes the item's depending items, and then the item"""
22- depending_items = dependent_item .dependent_to ()
23- if depending_items ['list' ]:
24- for item in depending_items ['list' ]:
25- delete_depending_items (item )
29+ depending_items = None
30+ try :
31+ depending_items = dependent_item .dependent_to ()
32+ if depending_items ['list' ]:
33+ for item in depending_items ['list' ]:
34+ delete_depending_items (item )
35+ except :
36+ print ("=== could not get item list %s" % dependent_item .homepage )
37+
2638 if dependent_item .protected :
2739 dependent_item .protect (False )
2840 try :
@@ -42,7 +54,7 @@ def delete_items(user):
4254 print ("=== finished deleting items owned by " + user .username )
4355
4456
45- def delete_groups (user ):
57+ def delete_groups (gis , user ):
4658 """deletes the user groups, and removes user from groups where user is a member of"""
4759 groups_for_deletion = gis .groups .get ('query=owner:' + user .username )
4860 if groups_for_deletion is not None :
@@ -63,22 +75,28 @@ def delete_groups(user):
6375 print ("=== finished deleting groups owned by " + user .username )
6476
6577
66- def delete_for_users ():
78+ def delete_for_users (gis , ignore_accounts , target_accounts ):
6779 """deletes items and groups for users in target_accounts, and ignore others"""
6880 for user in gis .users .search ():
6981 if user .username not in ignore_accounts and not user .username .startswith ("esri_" ):
7082 print ("-*-*-*-*-*-*-Delete groups & items & user for %s -*-*-*-*-*-" % user .username )
7183 delete_items (user )
72- delete_groups (user )
84+ delete_groups (gis , user )
7385 try :
7486 user .delete ()
7587 except :
7688 print ("could not delete user %s" % user .username )
77-
7889 elif user .username in target_accounts :
7990 print ("-*-*-*-*-*-*-Delete groups & items for %s -*-*-*-*-*-*-*-*-" % user .username )
8091 delete_items (user )
81- delete_groups (user )
92+ delete_groups (gis , user )
8293
8394 else :
8495 print ("-*-*-*-*-*-*-*-*-No Delete for %s -*-*-*-*-*-*-*-*-*-*-" % user .username )
96+
97+ def publish_data (gis , paths ):
98+ """publish sample data"""
99+ for path in paths :
100+ item = gis .content .add ({}, path )
101+ item .share (everyone = True )
102+ lyr = item .publish ()
0 commit comments