bluer-objects 6.167.1__py3-none-any.whl → 6.170.1__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.

Potentially problematic release.


This version of bluer-objects might be problematic. Click here for more details.

bluer_objects/__init__.py CHANGED
@@ -4,7 +4,7 @@ ICON = "🌀"
4
4
 
5
5
  DESCRIPTION = f"{ICON} Object management in Bash."
6
6
 
7
- VERSION = "6.167.1"
7
+ VERSION = "6.170.1"
8
8
 
9
9
  REPO_NAME = "bluer-objects"
10
10
 
@@ -16,6 +16,104 @@ from bluer_objects.logger import logger
16
16
  class S3Interface(StorageInterface):
17
17
  name = "s3"
18
18
 
19
+ def clear(
20
+ self,
21
+ do_dryrun: bool = True,
22
+ log: bool = True,
23
+ ) -> bool:
24
+ logger.info(
25
+ "{}.clear({})".format(
26
+ self.__class__.__name__,
27
+ "dryrun" if do_dryrun else "",
28
+ )
29
+ )
30
+
31
+ try:
32
+ s3 = boto3.client(
33
+ "s3",
34
+ endpoint_url=env.S3_STORAGE_ENDPOINT_URL,
35
+ aws_access_key_id=env.S3_STORAGE_AWS_ACCESS_KEY_ID,
36
+ aws_secret_access_key=env.S3_STORAGE_AWS_SECRET_ACCESS_KEY,
37
+ )
38
+
39
+ paginator = s3.get_paginator("list_objects_v2")
40
+ pages = paginator.paginate(
41
+ Bucket=env.S3_STORAGE_BUCKET,
42
+ Prefix="test",
43
+ )
44
+ except Exception as e:
45
+ logger.error(e)
46
+ return False
47
+
48
+ list_of_objects = sorted(
49
+ list(
50
+ set(
51
+ reduce(
52
+ lambda x, y: x + y,
53
+ [
54
+ [
55
+ obj["Key"].split("/", 1)[0]
56
+ for obj in page.get("Contents", [])
57
+ ]
58
+ for page in pages
59
+ ],
60
+ [],
61
+ )
62
+ )
63
+ )
64
+ )
65
+
66
+ logger.info(f"{len(list_of_objects)} object(s) to delete.")
67
+
68
+ for object_name in tqdm(list_of_objects):
69
+ if not self.delete(
70
+ object_name=object_name,
71
+ do_dryrun=do_dryrun,
72
+ ):
73
+ return False
74
+
75
+ return True
76
+
77
+ def delete(
78
+ self,
79
+ object_name: str,
80
+ do_dryrun: bool = True,
81
+ log: bool = True,
82
+ ) -> bool:
83
+ if log:
84
+ logger.info(
85
+ "{}.delete({}){}".format(
86
+ self.__class__.__name__,
87
+ object_name,
88
+ " dryrun" if do_dryrun else "",
89
+ )
90
+ )
91
+ if do_dryrun:
92
+ return True
93
+
94
+ try:
95
+ s3 = boto3.resource(
96
+ "s3",
97
+ endpoint_url=env.S3_STORAGE_ENDPOINT_URL,
98
+ aws_access_key_id=env.S3_STORAGE_AWS_ACCESS_KEY_ID,
99
+ aws_secret_access_key=env.S3_STORAGE_AWS_SECRET_ACCESS_KEY,
100
+ )
101
+ bucket = s3.Bucket(env.S3_STORAGE_BUCKET)
102
+
103
+ objects_to_delete = bucket.objects.filter(Prefix=f"{object_name}/")
104
+ delete_requests = [{"Key": obj.key} for obj in objects_to_delete]
105
+
106
+ if not delete_requests:
107
+ logger.warning(f"no files found under {object_name}.")
108
+ return True
109
+
110
+ bucket.delete_objects(Delete={"Objects": delete_requests})
111
+ except Exception as e:
112
+ logger.error(e)
113
+ return False
114
+
115
+ return True
116
+
19
117
  def download(
20
118
  self,
21
119
  object_name: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bluer_objects
3
- Version: 6.167.1
3
+ Version: 6.170.1
4
4
  Summary: 🌀 Object management in Bash.
5
5
  Home-page: https://github.com/kamangir/bluer-objects
6
6
  Author: Arash Abadpour (Kamangir)
@@ -64,6 +64,6 @@ pip install bluer-objects
64
64
 
65
65
  [![pylint](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/bluer-objects.svg)](https://pypi.org/project/bluer-objects/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/bluer-objects)](https://pypistats.org/packages/bluer-objects)
66
66
 
67
- built by 🌀 [`bluer README`](https://github.com/kamangir/bluer-objects/tree/main/bluer_objects/README), based on 🌀 [`bluer_objects-6.167.1`](https://github.com/kamangir/bluer-objects).
67
+ built by 🌀 [`bluer README`](https://github.com/kamangir/bluer-objects/tree/main/bluer_objects/README), based on 🌀 [`bluer_objects-6.170.1`](https://github.com/kamangir/bluer-objects).
68
68
 
69
69
  built by 🌀 [`blueness-3.118.1`](https://github.com/kamangir/blueness).
@@ -1,4 +1,4 @@
1
- bluer_objects/__init__.py,sha256=AAUp5OjrBuaaQpj180YEEwJlzYXPrzIw2nQwjyglchE,315
1
+ bluer_objects/__init__.py,sha256=Up7uiCfpaTfzOTrjFhSTVfEQQ9DtDCzeqOFsRvZ45Gw,315
2
2
  bluer_objects/__main__.py,sha256=Yqfov833_hJuRne19WrGhT5DWAPtdffpoMxeSXS7EGw,359
3
3
  bluer_objects/config.env,sha256=cpmtTuKHIBvVjX30MpAImFgwM0g24qTHwoO-lCJRInA,175
4
4
  bluer_objects/env.py,sha256=aImjtNh8NKaua2rpQVFXWp86QF7nY87fDuMOO14O58E,1956
@@ -124,7 +124,7 @@ bluer_objects/storage/WebDAVzip.py,sha256=Sd_rU57pJaRa05sKNQiMr85Bg3w7O5k8N1pSN1
124
124
  bluer_objects/storage/__init__.py,sha256=XosPRjB20wDS-QMwQtr3zqKC9UM7U8z-PHwySGBegcQ,1646
125
125
  bluer_objects/storage/__main__.py,sha256=vZI6rUkrekf1eYUgWOOUnFhl4qPfpByzwb-tihTOiIo,1776
126
126
  bluer_objects/storage/base.py,sha256=72I1zvlpbQbFU20TxqcTodR4m8PYgBPXMfteek8V0_A,1949
127
- bluer_objects/storage/s3.py,sha256=Xm0Dj2qQG8oEJyAM91NV9clDxGJxyN3FQughlFvP17w,5460
127
+ bluer_objects/storage/s3.py,sha256=evUFpPk6PUv1KCXTMq_QCbygqNk0YNAOQr_B4gYrjBE,8342
128
128
  bluer_objects/testing/__init__.py,sha256=DWY5ZtvCnHG_t9BDiqy_ArLOZi-nlyAtPVMLA1PPAMU,62
129
129
  bluer_objects/testing/__main__.py,sha256=hhJV9qn0V_8FxzNDcoHCHr4A7zf9UudnNGJCAPkTBGU,750
130
130
  bluer_objects/testing/functions.py,sha256=AXAfzWLcEPkbSYTehdahshjKJ45C4IJkRs_TgrHOntc,1355
@@ -156,8 +156,8 @@ bluer_objects/tests/test_storage_webdav_request.py,sha256=h2b8PeIx0-hQ2d6PmQcJZy
156
156
  bluer_objects/tests/test_storage_webdav_zip.py,sha256=C19qxhkcHyTwVFzW35vL85SOcXJPkqXXaWUNll0Uyqc,1017
157
157
  bluer_objects/tests/test_testing.py,sha256=d2NH435yqJBl9wmfMqGGd-f0Y0jsL2QhHUXkty9AwPA,235
158
158
  bluer_objects/tests/test_version.py,sha256=Lyf3PMcA22e17BNRk_2VgPrtao6dWEgVoXo68Uds8SE,75
159
- bluer_objects-6.167.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
160
- bluer_objects-6.167.1.dist-info/METADATA,sha256=39lUveyjYSXbX-0TDj4lbGVzeeoIYLrPk321iMuEXUI,3678
161
- bluer_objects-6.167.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
162
- bluer_objects-6.167.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
163
- bluer_objects-6.167.1.dist-info/RECORD,,
159
+ bluer_objects-6.170.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
160
+ bluer_objects-6.170.1.dist-info/METADATA,sha256=ELD0riVQPhS4tFIUH_2uAloiFQl-_KJuL7nc5xozizw,3678
161
+ bluer_objects-6.170.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
162
+ bluer_objects-6.170.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
163
+ bluer_objects-6.170.1.dist-info/RECORD,,