2424OUTPUT_FILE = "collections_ids.txt"
2525
2626# Load environment variables
27- path_to_env = os .path .join (os .getcwd (),"scripts" ,"migration" , ".env" )
27+ path_to_env = os .path .join (os .getcwd (), "scripts" , "migration" , ".env" )
2828config = dotenv_values (dotenv_path = path_to_env )
2929
3030
6060 "last_name" : "admin" ,
6161}
6262
63+
6364def get_clowder_v1_top_level_collections (headers ):
6465 endpoint = f"{ CLOWDER_V1 } /api/collections/topLevelCollections?superAdmin=true"
6566 response = requests .get (endpoint , headers = headers )
6667 user_collections = response .json ()
6768 return user_collections
6869
70+
6971def get_collection_v1_descendants (headers , collection_id ):
7072 descendant_ids = []
7173
@@ -75,17 +77,20 @@ def get_collection_v1_descendants(headers, collection_id):
7577 print (collection_json ["child_collection_ids" ])
7678 if int (collection_json ["childCollectionsCount" ]) > 0 :
7779 child_collections_ids = collection_json ["child_collection_ids" ]
78- descendant_ids = child_collections_ids [5 :- 1 ].split (', ' )
80+ descendant_ids = child_collections_ids [5 :- 1 ].split (", " )
7981 for i in range (0 , len (descendant_ids )):
8082 id = descendant_ids [i ]
8183 descendent_endpoint = f"{ CLOWDER_V1 } /api/collections/{ id } "
82- descendent_response = requests .get (descendent_endpoint , headers = headers , verify = False )
84+ descendent_response = requests .get (
85+ descendent_endpoint , headers = headers , verify = False
86+ )
8387 descendent_json = descendent_response .json ()
8488 if int (descendent_json ["childCollectionsCount" ]) > 0 :
8589 sub_descendants = get_collection_v1_descendants (headers , id )
8690 descendant_ids .extend (sub_descendants )
8791 return descendant_ids
8892
93+
8994def get_dataset_ids_in_v1_collection (headers , collection_id ):
9095 dataset_ids = []
9196 collection_endpoint = f"{ CLOWDER_V1 } /api/collections/{ collection_id } /datasets"
@@ -95,17 +100,23 @@ def get_dataset_ids_in_v1_collection(headers, collection_id):
95100 dataset_ids .append (dataset ["id" ])
96101 return dataset_ids
97102
103+
98104if __name__ == "__main__" :
99105 top_level_collections = get_clowder_v1_top_level_collections (clowder_headers_v1 )
100106 all_v1_collections = []
101107 for collection in top_level_collections :
102- print (f"Getting descendents for collection { collection ['name' ]} ({ collection ['id' ]} )" )
108+ print (
109+ f"Getting descendents for collection { collection ['name' ]} ({ collection ['id' ]} )"
110+ )
103111 all_v1_collections .append (collection ["id" ])
104112 if int (collection ["childCollectionsCount" ]) > 0 :
105- descendant_ids = get_collection_v1_descendants (clowder_headers_v1 , collection ["id" ])
113+ descendant_ids = get_collection_v1_descendants (
114+ clowder_headers_v1 , collection ["id" ]
115+ )
106116 all_v1_collections .extend (descendant_ids )
107- print (f"Added descendents for collection { collection ['name' ]} ({ collection ['id' ]} )" )
108-
117+ print (
118+ f"Added descendents for collection { collection ['name' ]} ({ collection ['id' ]} )"
119+ )
109120
110121 print (f"TOTAL V1 COLLECTIONS TO MIGRATE: { len (all_v1_collections )} " )
111122
0 commit comments