Skip to content

Commit 3838b5c

Browse files
author
Atma Mani
authored
Merge pull request #419 from Yongyao/yong9856-1887
Added script to reset contents of arcgis_python account on ArcGIS Online thanks @Yongyao
2 parents 0d01007 + 7bb6124 commit 3838b5c

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

misc/_common.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,39 @@
22
import 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

2027
def 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()

misc/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
print("-*-*-*-*-*-*-*-*-*-*-*Setup begins*-*-*-*-*-*-*-*-*-*-*-*-*-")
44

5-
delete_for_users()
5+
delete_for_users(gis_online, ignore_accounts_online, target_accounts_online)
6+
delete_for_users(gis_playground, ignore_accounts_playground, target_accounts_playground)
7+
# publish_data(gis_online, data_paths)
68

79
print("-*-*-*-*-*-*-*-*-*-*-*Setup ends*-*-*-*-*-*-*-*-*-*-*-*-*-*-")

misc/teardown.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
print("-*-*-*-*-*-*-*-*-*-*-*Teardown begins*-*-*-*-*-*-*-*-*-*-*-*-")
44

5-
delete_for_users()
5+
delete_for_users(gis_online, ignore_accounts_online, target_accounts_online)
6+
delete_for_users(gis_playground, ignore_accounts_playground, target_accounts_playground)
7+
# publish_data(gis_online, data_paths)
68

79
print("-*-*-*-*-*-*-*-*-*-*-*Teardown ends*-*-*-*-*-*-*-*-*-*-*-*-*-")

0 commit comments

Comments
 (0)