pyaws-s3 1.0.27__py3-none-any.whl → 1.0.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyaws_s3/s3.py +66 -8
- {pyaws_s3-1.0.27.dist-info → pyaws_s3-1.0.28.dist-info}/METADATA +1 -1
- pyaws_s3-1.0.28.dist-info/RECORD +7 -0
- pyaws_s3-1.0.27.dist-info/RECORD +0 -7
- {pyaws_s3-1.0.27.dist-info → pyaws_s3-1.0.28.dist-info}/WHEEL +0 -0
- {pyaws_s3-1.0.27.dist-info → pyaws_s3-1.0.28.dist-info}/licenses/LICENSE.md +0 -0
- {pyaws_s3-1.0.27.dist-info → pyaws_s3-1.0.28.dist-info}/top_level.txt +0 -0
pyaws_s3/s3.py
CHANGED
@@ -446,28 +446,52 @@ class S3Client:
|
|
446
446
|
logger.error(f"Error uploading file: {str(e)}")
|
447
447
|
raise Exception(f"Error uploading file: {str(e)}")
|
448
448
|
|
449
|
-
async def delete_all(self,
|
449
|
+
async def delete_all(self, **kwargs) -> None:
|
450
450
|
"""
|
451
451
|
Delete all files from an S3 bucket.
|
452
452
|
|
453
453
|
Args:
|
454
454
|
filter (str | None): Optional filter to delete specific files. If None, all files will be deleted.
|
455
|
+
prefix (str | None): Optional prefix to filter files by their key. If None, all files will be deleted.
|
456
|
+
|
455
457
|
Raises:
|
456
458
|
Exception: If there is an error deleting the files.
|
457
459
|
"""
|
458
460
|
try:
|
459
461
|
s3_client = self._get_s3_client()
|
462
|
+
|
463
|
+
prefix = kwargs.get("prefix", None)
|
464
|
+
filter = kwargs.get("filter", None)
|
465
|
+
|
466
|
+
if prefix is not None and not prefix.endswith('/'):
|
467
|
+
prefix += '/'
|
460
468
|
|
461
469
|
# List all objects in the bucket
|
462
|
-
objects =
|
470
|
+
objects = None
|
471
|
+
if prefix is None:
|
472
|
+
# List all objects in the bucket
|
473
|
+
objects = s3_client.list_objects_v2(Bucket=self.bucket_name)
|
474
|
+
else:
|
475
|
+
# List objects with the specified prefix
|
476
|
+
logger.info(f"Listing objects with prefix: {prefix}")
|
477
|
+
objects = s3_client.list_objects_v2(Bucket=self.bucket_name, Prefix=prefix)
|
463
478
|
|
464
479
|
# Check if the bucket contains any objects
|
465
480
|
if 'Contents' in objects:
|
466
481
|
for obj in objects['Contents']:
|
467
|
-
if filter
|
468
|
-
|
482
|
+
if filter is not None:
|
483
|
+
if filter in obj['Key']:
|
484
|
+
# Delete each object
|
485
|
+
s3_client.delete_object(Bucket=self.bucket_name, Key=obj['Key'])
|
486
|
+
print(f"Deleted {obj['Key']}")
|
487
|
+
else:
|
488
|
+
logger.info(f"Skipping {obj['Key']} as it does not match the filter: {filter}")
|
469
489
|
s3_client.delete_object(Bucket=self.bucket_name, Key=obj['Key'])
|
470
490
|
print(f"Deleted {obj['Key']}")
|
491
|
+
else:
|
492
|
+
logger.info("No objects found in the bucket.")
|
493
|
+
|
494
|
+
print("All files deleted successfully.")
|
471
495
|
except Exception as e:
|
472
496
|
logger.error(f"Error deleting files: {str(e)}")
|
473
497
|
raise Exception(f"Error deleting files: {str(e)}")
|
@@ -619,13 +643,14 @@ class S3Client:
|
|
619
643
|
except Exception as e:
|
620
644
|
logger.error(f"Error downloading file: {str(e)}")
|
621
645
|
raise Exception(f"Error downloading file: {str(e)}")
|
622
|
-
|
646
|
+
|
623
647
|
def list_files(self, *args: Any, **kwargs : Any) -> list[str]:
|
624
648
|
"""
|
625
649
|
List all files in the S3 bucket.
|
626
650
|
|
627
651
|
Args:
|
628
652
|
filter (str | None): Optional filter to list specific files. If None, all files will be listed.
|
653
|
+
prefix (str | None): Optional prefix to filter files by their key. If None, all files will be listed.
|
629
654
|
Raises:
|
630
655
|
Exception: If there is an error listing the files.
|
631
656
|
Returns:
|
@@ -639,9 +664,14 @@ class S3Client:
|
|
639
664
|
if prefix is None:
|
640
665
|
raise Exception("Prefix is None")
|
641
666
|
|
667
|
+
if prefix is not None and not prefix.endswith('/'):
|
668
|
+
prefix += '/'
|
669
|
+
|
642
670
|
filter = kwargs.get("filter", None)
|
643
671
|
|
644
672
|
s3_client = self._get_s3_client()
|
673
|
+
|
674
|
+
logger.info(f"Listing objects with prefix: {prefix}")
|
645
675
|
objects = s3_client.list_objects_v2(Bucket=self.bucket_name, Prefix=prefix)
|
646
676
|
|
647
677
|
# Check if the bucket contains any objects
|
@@ -649,7 +679,6 @@ class S3Client:
|
|
649
679
|
if 'Contents' in objects:
|
650
680
|
for obj in objects['Contents']:
|
651
681
|
if obj['Key']:
|
652
|
-
# Log the object key
|
653
682
|
if filter is not None:
|
654
683
|
if filter in obj['Key']:
|
655
684
|
logger.info(f"Object: {obj['Key']}")
|
@@ -661,12 +690,14 @@ class S3Client:
|
|
661
690
|
logger.error(f"Error listing files: {str(e)}")
|
662
691
|
raise Exception(f"Error listing files: {str(e)}")
|
663
692
|
|
664
|
-
def delete_file(self, *args : Any) -> None:
|
693
|
+
def delete_file(self, *args : Any, **kwargs) -> None:
|
665
694
|
"""
|
666
695
|
Delete a file from the S3 bucket.
|
667
696
|
|
668
697
|
Args:
|
669
698
|
object_name (str): The name of the S3 object to delete.
|
699
|
+
prefix (str | None): Optional prefix to filter files by their key. If None, all files will be deleted.
|
700
|
+
filter (str | None): Optional filter to delete specific files. If None, the specified
|
670
701
|
Raises:
|
671
702
|
Exception: If there is an error deleting the file.
|
672
703
|
"""
|
@@ -675,8 +706,35 @@ class S3Client:
|
|
675
706
|
if object_name is None:
|
676
707
|
raise Exception("Object name is None")
|
677
708
|
|
709
|
+
prefix = kwargs.get("prefix", None)
|
710
|
+
if prefix is not None and not prefix.endswith('/'):
|
711
|
+
prefix += '/'
|
712
|
+
|
713
|
+
filter = kwargs.get("filter", None)
|
714
|
+
|
678
715
|
s3_client = self._get_s3_client()
|
679
|
-
|
716
|
+
|
717
|
+
objects = None
|
718
|
+
if prefix is None:
|
719
|
+
# List all objects in the bucket
|
720
|
+
objects = s3_client.list_objects_v2(Bucket=self.bucket_name)
|
721
|
+
else:
|
722
|
+
# List objects with the specified prefix
|
723
|
+
logger.info(f"Listing objects with prefix: {prefix}")
|
724
|
+
objects = s3_client.list_objects_v2(Bucket=self.bucket_name, Prefix=prefix)
|
725
|
+
|
726
|
+
# Check if the bucket contains any objects
|
727
|
+
if 'Contents' in objects:
|
728
|
+
for obj in objects['Contents']:
|
729
|
+
if filter is not None:
|
730
|
+
if filter in obj['Key']:
|
731
|
+
# Delete each object
|
732
|
+
s3_client.delete_object(Bucket=self.bucket_name, Key=obj['Key'])
|
733
|
+
print(f"Deleted {obj['Key']}")
|
734
|
+
else:
|
735
|
+
# If no objects match the filter, delete the specified object
|
736
|
+
s3_client.delete_object(Bucket=self.bucket_name, Key=object_name)
|
737
|
+
print(f"Deleted {object_name}")
|
680
738
|
except Exception as e:
|
681
739
|
logger.error(f"Error deleting file: {str(e)}")
|
682
740
|
raise Exception(f"Error deleting file: {str(e)}")
|
@@ -0,0 +1,7 @@
|
|
1
|
+
pyaws_s3/__init__.py,sha256=Tr7xJiCKOMWYydOJ4kxHlA7AR1X3pRsJ8MjxJev2wsw,24
|
2
|
+
pyaws_s3/s3.py,sha256=hzmhviS6DuTRNbb-Mq4BlvEcTFxGJjx1PbiOCyWKTKI,30697
|
3
|
+
pyaws_s3-1.0.28.dist-info/licenses/LICENSE.md,sha256=7WXohDebeZpcVn_nH2aIaLhFZRvZBdcPSqWsO12lhwM,1074
|
4
|
+
pyaws_s3-1.0.28.dist-info/METADATA,sha256=hXYibpkyHggfIWWysII8-kDW-Lr2YLxyDEjjN7Cjujg,5464
|
5
|
+
pyaws_s3-1.0.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
pyaws_s3-1.0.28.dist-info/top_level.txt,sha256=MxSSC4Q8Vr32wKgrUAlwT4BTXwqUaG_CAWoBuPeXYjQ,9
|
7
|
+
pyaws_s3-1.0.28.dist-info/RECORD,,
|
pyaws_s3-1.0.27.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
pyaws_s3/__init__.py,sha256=Tr7xJiCKOMWYydOJ4kxHlA7AR1X3pRsJ8MjxJev2wsw,24
|
2
|
-
pyaws_s3/s3.py,sha256=x_7M_3qTPyoExn6-Hw790YI4DQLFbIyBInXTYjDY3jQ,27780
|
3
|
-
pyaws_s3-1.0.27.dist-info/licenses/LICENSE.md,sha256=7WXohDebeZpcVn_nH2aIaLhFZRvZBdcPSqWsO12lhwM,1074
|
4
|
-
pyaws_s3-1.0.27.dist-info/METADATA,sha256=aHF-ijVr5cQGXQYOBIMeBT9MEjNmZx-pJ9zPIO_D5kc,5464
|
5
|
-
pyaws_s3-1.0.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
pyaws_s3-1.0.27.dist-info/top_level.txt,sha256=MxSSC4Q8Vr32wKgrUAlwT4BTXwqUaG_CAWoBuPeXYjQ,9
|
7
|
-
pyaws_s3-1.0.27.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|