2
2
import datetime
3
3
4
4
"""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' ,
6
10
'atma.mani' , 'john.yaist' , 'bill.major' , 'YJiang' ,
7
11
'rohit.singh' , 'rohitgeo' , 'gbochenek_python' ,
8
12
'system_publisher' , 'admin' , 'portaladmin' ,
9
13
'Demo_User' , 'First_User' , 'Second_User' ,
10
14
'api_data_owner' , 'arcgis_python' , 'temp_execution' ]
11
15
12
16
"""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' ]
14
19
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' ]
18
22
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' )
19
26
20
27
def delete_depending_items (dependent_item ):
21
28
"""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
+
26
38
if dependent_item .protected :
27
39
dependent_item .protect (False )
28
40
try :
@@ -42,7 +54,7 @@ def delete_items(user):
42
54
print ("=== finished deleting items owned by " + user .username )
43
55
44
56
45
- def delete_groups (user ):
57
+ def delete_groups (gis , user ):
46
58
"""deletes the user groups, and removes user from groups where user is a member of"""
47
59
groups_for_deletion = gis .groups .get ('query=owner:' + user .username )
48
60
if groups_for_deletion is not None :
@@ -63,22 +75,28 @@ def delete_groups(user):
63
75
print ("=== finished deleting groups owned by " + user .username )
64
76
65
77
66
- def delete_for_users ():
78
+ def delete_for_users (gis , ignore_accounts , target_accounts ):
67
79
"""deletes items and groups for users in target_accounts, and ignore others"""
68
80
for user in gis .users .search ():
69
81
if user .username not in ignore_accounts and not user .username .startswith ("esri_" ):
70
82
print ("-*-*-*-*-*-*-Delete groups & items & user for %s -*-*-*-*-*-" % user .username )
71
83
delete_items (user )
72
- delete_groups (user )
84
+ delete_groups (gis , user )
73
85
try :
74
86
user .delete ()
75
87
except :
76
88
print ("could not delete user %s" % user .username )
77
-
78
89
elif user .username in target_accounts :
79
90
print ("-*-*-*-*-*-*-Delete groups & items for %s -*-*-*-*-*-*-*-*-" % user .username )
80
91
delete_items (user )
81
- delete_groups (user )
92
+ delete_groups (gis , user )
82
93
83
94
else :
84
95
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