11import json
2- import requests
32from typing import List
43
5- from databusclient .api .utils import get_databus_id_parts_from_uri , fetch_databus_jsonld
4+ import requests
5+
6+ from databusclient .api .utils import fetch_databus_jsonld , get_databus_id_parts_from_uri
7+
68
79def _confirm_delete (databusURI : str ) -> str :
810 """
@@ -17,9 +19,17 @@ def _confirm_delete(databusURI: str) -> str:
1719 - "cancel" if the user chooses to cancel the entire deletion process
1820 """
1921 print (f"Are you sure you want to delete: { databusURI } ?" )
20- print ("\n This action is irreversible and will permanently remove the resource and all its data." )
22+ print (
23+ "\n This action is irreversible and will permanently remove the resource and all its data."
24+ )
2125 while True :
22- choice = input ("Type 'yes'/'y' to confirm, 'skip'/'s' to skip this resource, or 'cancel'/'c' to abort: " ).strip ().lower ()
26+ choice = (
27+ input (
28+ "Type 'yes'/'y' to confirm, 'skip'/'s' to skip this resource, or 'cancel'/'c' to abort: "
29+ )
30+ .strip ()
31+ .lower ()
32+ )
2333 if choice in ("yes" , "y" ):
2434 return "confirm"
2535 elif choice in ("skip" , "s" ):
@@ -30,7 +40,9 @@ def _confirm_delete(databusURI: str) -> str:
3040 print ("Invalid input. Please type 'yes'/'y', 'skip'/'s', or 'cancel'/'c'." )
3141
3242
33- def _delete_resource (databusURI : str , databus_key : str , dry_run : bool = False , force : bool = False ):
43+ def _delete_resource (
44+ databusURI : str , databus_key : str , dry_run : bool = False , force : bool = False
45+ ):
3446 """
3547 Delete a single Databus resource (version, artifact, group).
3648
@@ -56,10 +68,7 @@ def _delete_resource(databusURI: str, databus_key: str, dry_run: bool = False, f
5668 if databus_key is None :
5769 raise ValueError ("Databus API key must be provided for deletion" )
5870
59- headers = {
60- "accept" : "*/*" ,
61- "X-API-KEY" : databus_key
62- }
71+ headers = {"accept" : "*/*" , "X-API-KEY" : databus_key }
6372
6473 if dry_run :
6574 print (f"[DRY RUN] Would delete: { databusURI } " )
@@ -70,10 +79,14 @@ def _delete_resource(databusURI: str, databus_key: str, dry_run: bool = False, f
7079 if response .status_code in (200 , 204 ):
7180 print (f"Successfully deleted: { databusURI } " )
7281 else :
73- raise Exception (f"Failed to delete { databusURI } : { response .status_code } - { response .text } " )
82+ raise Exception (
83+ f"Failed to delete { databusURI } : { response .status_code } - { response .text } "
84+ )
7485
7586
76- def _delete_list (databusURIs : List [str ], databus_key : str , dry_run : bool = False , force : bool = False ):
87+ def _delete_list (
88+ databusURIs : List [str ], databus_key : str , dry_run : bool = False , force : bool = False
89+ ):
7790 """
7891 Delete a list of Databus resources.
7992
@@ -85,7 +98,9 @@ def _delete_list(databusURIs: List[str], databus_key: str, dry_run: bool = False
8598 _delete_resource (databusURI , databus_key , dry_run = dry_run , force = force )
8699
87100
88- def _delete_artifact (databusURI : str , databus_key : str , dry_run : bool = False , force : bool = False ):
101+ def _delete_artifact (
102+ databusURI : str , databus_key : str , dry_run : bool = False , force : bool = False
103+ ):
89104 """
90105 Delete an artifact and all its versions.
91106
@@ -121,7 +136,10 @@ def _delete_artifact(databusURI: str, databus_key: str, dry_run: bool = False, f
121136 # Finally, delete the artifact itself
122137 _delete_resource (databusURI , databus_key , dry_run = dry_run , force = force )
123138
124- def _delete_group (databusURI : str , databus_key : str , dry_run : bool = False , force : bool = False ):
139+
140+ def _delete_group (
141+ databusURI : str , databus_key : str , dry_run : bool = False , force : bool = False
142+ ):
125143 """
126144 Delete a group and all its artifacts and versions.
127145
@@ -154,13 +172,14 @@ def _delete_group(databusURI: str, databus_key: str, dry_run: bool = False, forc
154172 # Finally, delete the group itself
155173 _delete_resource (databusURI , databus_key , dry_run = dry_run , force = force )
156174
175+
157176def delete (databusURIs : List [str ], databus_key : str , dry_run : bool , force : bool ):
158177 """
159178 Delete a dataset from the databus.
160179
161180 Delete a group, artifact, or version identified by the given databus URI.
162181 Will recursively delete all data associated with the dataset.
163-
182+
164183 Parameters:
165184 - databusURIs: List of full databus URIs of the resources to delete
166185 - databus_key: Databus API key to authenticate the deletion requests
@@ -169,7 +188,9 @@ def delete(databusURIs: List[str], databus_key: str, dry_run: bool, force: bool)
169188 """
170189
171190 for databusURI in databusURIs :
172- _host , _account , group , artifact , version , file = get_databus_id_parts_from_uri (databusURI )
191+ _host , _account , group , artifact , version , file = get_databus_id_parts_from_uri (
192+ databusURI
193+ )
173194
174195 if group == "collections" and artifact is not None :
175196 print (f"Deleting collection: { databusURI } " )
0 commit comments