|
1 |
| - |
2 | 1 | __copyright__ = """
|
3 | 2 |
|
4 | 3 | Copyright 2020 Samapriya Roy
|
|
22 | 21 | import itertools
|
23 | 22 |
|
24 | 23 | # Empty Lists
|
25 |
| -folder_paths=[] |
26 |
| -image_list=[] |
27 |
| -collection_list=[] |
28 |
| -table_list=[] |
| 24 | +folder_paths = [] |
| 25 | +image_list = [] |
| 26 | +collection_list = [] |
| 27 | +table_list = [] |
29 | 28 |
|
30 | 29 | # Recursive folder paths
|
31 | 30 | def recursive(path):
|
32 |
| - if ee.data.getInfo(path)['type'].lower()=='folder': |
33 |
| - children = ee.data.getList({'id': path}) |
| 31 | + if ee.data.getInfo(path)["type"].lower() == "folder": |
| 32 | + children = ee.data.getList({"id": path}) |
34 | 33 | folder_paths.append(path)
|
35 |
| - val=[child['type'].lower()=='folder' for child in children] |
36 |
| - while len(val)>0 and True in val: |
| 34 | + val = [child["type"].lower() == "folder" for child in children] |
| 35 | + while len(val) > 0 and True in val: |
37 | 36 | for child in children:
|
38 |
| - if child['type'].lower()=='folder': |
39 |
| - folder_paths.append(child['id']) |
40 |
| - children = ee.data.getList({'id': child['id']}) |
41 |
| - val=[child['type'].lower()=='folder' for child in children] |
42 |
| - print('Total folders: {}'.format(len(folder_paths))) |
| 37 | + if child["type"].lower() == "folder": |
| 38 | + folder_paths.append(child["id"]) |
| 39 | + children = ee.data.getList({"id": child["id"]}) |
| 40 | + val = [child["type"].lower() == "folder" for child in children] |
| 41 | + print("Total folders: {}".format(len(folder_paths))) |
43 | 42 | return folder_paths
|
44 | 43 |
|
| 44 | + |
45 | 45 | # folder parse
|
46 | 46 | def fparse(path):
|
47 | 47 | ee.Initialize()
|
48 |
| - if ee.data.getInfo(path)['type'].lower()=='folder': |
49 |
| - gee_folder_path=recursive(path) |
| 48 | + if ee.data.getInfo(path)["type"].lower() == "folder": |
| 49 | + gee_folder_path = recursive(path) |
50 | 50 | for folders in gee_folder_path:
|
51 |
| - children = ee.data.getList({'id': folders}) |
| 51 | + children = ee.data.getList({"id": folders}) |
52 | 52 | for child in children:
|
53 |
| - if child['type'].lower()=='imagecollection': |
54 |
| - collection_list.append(child['id']) |
55 |
| - elif child['type'].lower()=='image': |
56 |
| - image_list.append(child['id']) |
57 |
| - elif child['type'].lower()=='table': |
58 |
| - table_list.append(child['id']) |
59 |
| - elif ee.data.getInfo(path)['type'].lower()=='image': |
| 53 | + if child["type"].lower() == "imagecollection": |
| 54 | + collection_list.append(child["id"]) |
| 55 | + elif child["type"].lower() == "image": |
| 56 | + image_list.append(child["id"]) |
| 57 | + elif child["type"].lower() == "table": |
| 58 | + table_list.append(child["id"]) |
| 59 | + elif ee.data.getInfo(path)["type"].lower() == "image": |
60 | 60 | image_list.append(path)
|
61 |
| - elif ee.data.getInfo(path)['type'].lower()=='image_collection': |
| 61 | + elif ee.data.getInfo(path)["type"].lower() == "image_collection": |
62 | 62 | collection_list.append(path)
|
63 |
| - elif ee.data.getInfo(path)['type'].lower()=='table': |
| 63 | + elif ee.data.getInfo(path)["type"].lower() == "table": |
64 | 64 | table_list.append(path)
|
65 | 65 | else:
|
66 |
| - print(ee.data.getInfo(path)['type'].lower()) |
67 |
| - return [collection_list,table_list,image_list,folder_paths] |
| 66 | + print(ee.data.getInfo(path)["type"].lower()) |
| 67 | + return [collection_list, table_list, image_list, folder_paths] |
68 | 68 |
|
69 | 69 |
|
70 | 70 | ##request type of asset, asset path and user to give permission
|
71 |
| -def access(collection_path,user,role): |
| 71 | +def access(collection_path, user, role): |
72 | 72 | ee.Initialize()
|
73 |
| - asset_list=fparse(collection_path) |
| 73 | + asset_list = fparse(collection_path) |
74 | 74 | asset_names = list(itertools.chain(*asset_list))
|
75 |
| - print('Changing permission for total of '+str(len(asset_names))+' items.....') |
76 |
| - for count,init in enumerate(asset_names): |
77 |
| - print('Working on ===> {}'.format(init)) |
| 75 | + print("Changing permission for total of " + str(len(asset_names)) + " items.....") |
| 76 | + for count, init in enumerate(asset_names): |
| 77 | + print("Working on ===> {}".format(init)) |
78 | 78 | acl = ee.data.getAssetAcl(init)
|
79 |
| - if role=='reader': |
80 |
| - if not user in acl['readers']: |
81 |
| - baselist=acl['readers'] |
| 79 | + if role == "reader": |
| 80 | + if not user in acl["readers"]: |
| 81 | + baselist = acl["readers"] |
82 | 82 | baselist.append(user)
|
83 |
| - acl['readers']=baselist |
84 |
| - acl['owners']=[] |
| 83 | + acl["readers"] = baselist |
| 84 | + acl["owners"] = [] |
85 | 85 | try:
|
86 | 86 | ee.data.setAssetAcl(init, json.dumps(acl))
|
87 | 87 | except Exception as e:
|
88 | 88 | print(e)
|
89 | 89 | else:
|
90 |
| - print('user already has read access to this asset:SKIPPING') |
91 |
| - if role=='writer': |
92 |
| - if not user in acl['writers']: |
93 |
| - baselist=acl['writers'] |
| 90 | + print("user already has read access to this asset:SKIPPING") |
| 91 | + if role == "writer": |
| 92 | + if not user in acl["writers"]: |
| 93 | + baselist = acl["writers"] |
94 | 94 | baselist.append(user)
|
95 |
| - acl['readers']=baselist |
96 |
| - acl['owners']=[] |
| 95 | + acl["readers"] = baselist |
| 96 | + acl["owners"] = [] |
97 | 97 | try:
|
98 | 98 | ee.data.setAssetAcl(init, json.dumps(acl))
|
99 | 99 | except Exception as e:
|
100 | 100 | print(e)
|
101 | 101 | else:
|
102 |
| - print('user already has write access to this asset:SKIPPING') |
103 |
| - if role=='delete': |
104 |
| - if not user in acl['readers']: |
105 |
| - print('user does not have permission:SKIPPING') |
| 102 | + print("user already has write access to this asset:SKIPPING") |
| 103 | + if role == "delete": |
| 104 | + if not user in acl["readers"]: |
| 105 | + print("user does not have permission:SKIPPING") |
106 | 106 | else:
|
107 |
| - baselist=acl['readers'] |
| 107 | + baselist = acl["readers"] |
108 | 108 | baselist.remove(user)
|
109 |
| - acl['readers']=baselist |
110 |
| - acl['owners']=[] |
| 109 | + acl["readers"] = baselist |
| 110 | + acl["owners"] = [] |
111 | 111 | try:
|
112 | 112 | ee.data.setAssetAcl(init, json.dumps(acl))
|
113 | 113 | except Exception as e:
|
|
0 commit comments