@@ -132,11 +132,15 @@ def bucket_name_part(length: int) -> str:
132
132
logger .info ('name_part: %s' , name_part )
133
133
return name_part
134
134
135
+
135
136
T = TypeVar ('T' )
137
+
138
+
136
139
def wrap_iterables (generators : list [Iterable [T ]]):
137
140
for g in generators :
138
141
yield from g
139
142
143
+
140
144
@dataclass
141
145
class Api :
142
146
account_id : str
@@ -224,20 +228,26 @@ def clean_buckets(self, quick=False):
224
228
TooManyRequests ,
225
229
max_tries = 8 ,
226
230
)
227
- def clean_bucket (self , bucket_object : Bucket | str , only_files : bool = False , only_folders : list [str ] | None = None , ignore_retentions : bool = False ):
231
+ def clean_bucket (
232
+ self ,
233
+ bucket_object : Bucket | str ,
234
+ only_files : bool = False ,
235
+ only_folders : list [str ] | None = None ,
236
+ ignore_retentions : bool = False ,
237
+ ):
228
238
"""
229
239
Clean contents of bucket, by default also deleting the bucket.
230
240
231
- Args:
232
- bucket (Bucket | str): Bucket object or name
233
- only_files (bool): If to only delete files and not the bucket
241
+ Args:
242
+ bucket (Bucket | str): Bucket object or name
243
+ only_files (bool): If to only delete files and not the bucket
234
244
only_folders (list[str] | None): If not None, filter to only files in given folders.
235
245
ignore_retentions (bool): If deletion should happen regardless of files' retention mode.
236
246
"""
237
247
bucket : Bucket
238
248
if isinstance (bucket_object , str ):
239
249
bucket = self .api .get_bucket_by_name (bucket_object )
240
- else :
250
+ else :
241
251
bucket = bucket_object
242
252
243
253
if not only_files :
@@ -253,7 +263,16 @@ def clean_bucket(self, bucket_object: Bucket | str, only_files: bool = False, on
253
263
254
264
file_versions : Iterable [Any ]
255
265
if only_folders :
256
- file_versions = wrap_iterables ([bucket .ls (latest_only = False , recursive = True , folder_to_list = folder ,) for folder in only_folders ])
266
+ file_versions = wrap_iterables (
267
+ [
268
+ bucket .ls (
269
+ latest_only = False ,
270
+ recursive = True ,
271
+ folder_to_list = folder ,
272
+ )
273
+ for folder in only_folders
274
+ ]
275
+ )
257
276
else :
258
277
file_versions = bucket .ls (latest_only = False , recursive = True )
259
278
0 commit comments