databutton 0.38.0__py3-none-any.whl → 0.38.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.
- databutton/experimental/folder/folder.py +24 -21
- databutton/version.py +1 -1
- {databutton-0.38.0.dist-info → databutton-0.38.1.dist-info}/METADATA +1 -1
- {databutton-0.38.0.dist-info → databutton-0.38.1.dist-info}/RECORD +6 -6
- {databutton-0.38.0.dist-info → databutton-0.38.1.dist-info}/LICENSE +0 -0
- {databutton-0.38.0.dist-info → databutton-0.38.1.dist-info}/WHEEL +0 -0
@@ -1,44 +1,47 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
1
|
+
from io import BytesIO
|
2
|
+
from pathlib import Path
|
3
|
+
from zipfile import ZIP_DEFLATED, ZipFile
|
4
4
|
|
5
5
|
import databutton as db
|
6
6
|
|
7
7
|
|
8
|
+
def normalize_path(path: str) -> Path:
|
9
|
+
"""Normalize and return the absolute path."""
|
10
|
+
return Path(path).resolve()
|
11
|
+
|
12
|
+
|
8
13
|
def zip_folder_to_bytes(folder_path: str) -> bytes:
|
9
14
|
"""Zip the contents of a folder and return as bytes."""
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
os.path.relpath(file_path, os.path.join(folder_path, "..")),
|
18
|
-
)
|
15
|
+
normalized_folder_path = normalize_path(folder_path)
|
16
|
+
zip_bytes = BytesIO() # Use BytesIO as a buffer
|
17
|
+
with ZipFile(zip_bytes, "w", ZIP_DEFLATED) as zipf:
|
18
|
+
for file_path in normalized_folder_path.rglob("*"):
|
19
|
+
if file_path.is_file():
|
20
|
+
archive_name = file_path.relative_to(normalized_folder_path).as_posix()
|
21
|
+
zipf.write(file_path, archive_name)
|
19
22
|
zip_bytes.seek(0) # Go to the start of the BytesIO buffer
|
20
23
|
return zip_bytes.getvalue()
|
21
24
|
|
22
25
|
|
23
26
|
def unzip_bytes_to_folder(bytes_data: bytes, extract_path: str):
|
24
27
|
"""Unzip bytes into a folder."""
|
25
|
-
|
26
|
-
|
27
|
-
zip_bytes =
|
28
|
-
with
|
29
|
-
zip_ref.extractall(
|
28
|
+
normalized_extract_path = normalize_path(extract_path)
|
29
|
+
normalized_extract_path.mkdir(parents=True, exist_ok=True)
|
30
|
+
zip_bytes = BytesIO(bytes_data)
|
31
|
+
with ZipFile(zip_bytes, "r") as zip_ref:
|
32
|
+
zip_ref.extractall(normalized_extract_path)
|
30
33
|
|
31
34
|
|
32
35
|
def upload(key: str, folder_path: str):
|
33
36
|
"""Zip and upload a folder to blob storage."""
|
34
|
-
|
37
|
+
normalized_folder_path = normalize_path(folder_path)
|
38
|
+
zipped_bytes = zip_folder_to_bytes(normalized_folder_path.as_posix())
|
35
39
|
db.storage.binary.put(key, zipped_bytes)
|
36
40
|
|
37
41
|
|
38
42
|
def download(key: str, folder_path: str):
|
39
43
|
"""Download and unzip a folder from blob storage."""
|
44
|
+
normalized_folder_path = normalize_path(folder_path)
|
40
45
|
zipped_bytes = db.storage.binary.get(key)
|
41
46
|
if zipped_bytes is not None:
|
42
|
-
|
43
|
-
os.makedirs(folder_path, exist_ok=True)
|
44
|
-
unzip_bytes_to_folder(zipped_bytes, folder_path)
|
47
|
+
unzip_bytes_to_folder(zipped_bytes, normalized_folder_path.as_posix())
|
databutton/version.py
CHANGED
@@ -4,7 +4,7 @@ databutton/experimental/__init__.py,sha256=S5AFlCNuvWf5HR2BUs_uzNd-GmjbpVm6eA__D
|
|
4
4
|
databutton/experimental/auth/__init__.py,sha256=hqMbUs9GIVW-bJrayhWzdmSLkmU1wvFHDp6jMKwQrWc,73
|
5
5
|
databutton/experimental/auth/get_user.py,sha256=qi6nkG35PRgeljV4J-cHdEE4nhfwJHOYv93tBXR5A9I,3314
|
6
6
|
databutton/experimental/folder/__init__.py,sha256=27dUyREJ-08xP4OmQUtAyWWz7_hWEat6ajqiJ2xgyeo,71
|
7
|
-
databutton/experimental/folder/folder.py,sha256=
|
7
|
+
databutton/experimental/folder/folder.py,sha256=Qr-Uo-QITVADxh22Da635HXBRdHmkfb7vQMa4NMEYOA,1793
|
8
8
|
databutton/internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
databutton/internal/auth.py,sha256=MY4S7Gvb6xufmZ0SssZka0eY_18lJbxHW61cHrisnro,3182
|
10
10
|
databutton/internal/byteutils.py,sha256=2SYQxhbK1Kj__u_ap01kPpeb1b_bcZAXSz6aqWwetUA,740
|
@@ -24,8 +24,8 @@ databutton/secrets/__init__.py,sha256=sI0okrfRBs2l5tcLTrKc9uUfPVVRMM9D7WED8p226t
|
|
24
24
|
databutton/secrets/secrets.py,sha256=pehXsD09iKTxHaNQJ6awvIHXgRXBJrf4Xhrc11ZUeOk,3427
|
25
25
|
databutton/storage/__init__.py,sha256=7ZNd4eQQ7lYYIe1MqCuFbFF1aAVCuj2c_zmJfaPVlDY,252
|
26
26
|
databutton/storage/storage.py,sha256=x9LTyoAfLTWFCoy7XhA0tVUTkjldx8gYax09RkhMR1Q,20369
|
27
|
-
databutton/version.py,sha256=
|
28
|
-
databutton-0.38.
|
29
|
-
databutton-0.38.
|
30
|
-
databutton-0.38.
|
31
|
-
databutton-0.38.
|
27
|
+
databutton/version.py,sha256=JqDMA3jkMCNbd9Wfecx-3HRU9BYk9SnrACKSZwM4D4U,175
|
28
|
+
databutton-0.38.1.dist-info/LICENSE,sha256=c7h4pcVZapFEmqWoRTRv_S1P_aibrtDobqmlR-QtMUk,45
|
29
|
+
databutton-0.38.1.dist-info/METADATA,sha256=6sesx89PFsYmeTsEEVoXG67lpCEy-_kDHiL4KX36_Ws,2753
|
30
|
+
databutton-0.38.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
31
|
+
databutton-0.38.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|