databutton 0.37.9__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.
@@ -1,3 +1,3 @@
1
- from . import auth
1
+ from . import auth, folder
2
2
 
3
- __all__ = ["auth"]
3
+ __all__ = ["auth", "folder"]
@@ -0,0 +1,3 @@
1
+ from .folder import download, upload
2
+
3
+ __all__ = ["upload", "download"]
@@ -0,0 +1,47 @@
1
+ from io import BytesIO
2
+ from pathlib import Path
3
+ from zipfile import ZIP_DEFLATED, ZipFile
4
+
5
+ import databutton as db
6
+
7
+
8
+ def normalize_path(path: str) -> Path:
9
+ """Normalize and return the absolute path."""
10
+ return Path(path).resolve()
11
+
12
+
13
+ def zip_folder_to_bytes(folder_path: str) -> bytes:
14
+ """Zip the contents of a folder and return as bytes."""
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)
22
+ zip_bytes.seek(0) # Go to the start of the BytesIO buffer
23
+ return zip_bytes.getvalue()
24
+
25
+
26
+ def unzip_bytes_to_folder(bytes_data: bytes, extract_path: str):
27
+ """Unzip bytes into a folder."""
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)
33
+
34
+
35
+ def upload(key: str, folder_path: str):
36
+ """Zip and upload a folder to blob storage."""
37
+ normalized_folder_path = normalize_path(folder_path)
38
+ zipped_bytes = zip_folder_to_bytes(normalized_folder_path.as_posix())
39
+ db.storage.binary.put(key, zipped_bytes)
40
+
41
+
42
+ def download(key: str, folder_path: str):
43
+ """Download and unzip a folder from blob storage."""
44
+ normalized_folder_path = normalize_path(folder_path)
45
+ zipped_bytes = db.storage.binary.get(key)
46
+ if zipped_bytes is not None:
47
+ unzip_bytes_to_folder(zipped_bytes, normalized_folder_path.as_posix())
databutton/version.py CHANGED
@@ -5,4 +5,4 @@ This module contains project version information.
5
5
  .. moduleauthor:: Databutton <support@databutton.com>
6
6
  """
7
7
 
8
- __version__ = "0.37.9"
8
+ __version__ = "0.38.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: databutton
3
- Version: 0.37.9
3
+ Version: 0.38.1
4
4
  Summary: The CLI for databutton.com
5
5
  License: Databutton
6
6
  Author: Databutton
@@ -1,8 +1,10 @@
1
1
  databutton/__init__.py,sha256=h5GdA1J_7UCaGxMFbobohHAiweUvqhOnm7TQ7cPaeGU,418
2
2
  databutton/cachetools.py,sha256=soq0BDkE_YNaybBx-fI4pJ1x8k9KuotZ0f_OuZCCI9k,3554
3
- databutton/experimental/__init__.py,sha256=e2vI2X5xQxTPZtsiYXnO91y52BQ4tTx1zbbvDnFK8tk,39
3
+ databutton/experimental/__init__.py,sha256=S5AFlCNuvWf5HR2BUs_uzNd-GmjbpVm6eA__DLMUpPU,57
4
4
  databutton/experimental/auth/__init__.py,sha256=hqMbUs9GIVW-bJrayhWzdmSLkmU1wvFHDp6jMKwQrWc,73
5
5
  databutton/experimental/auth/get_user.py,sha256=qi6nkG35PRgeljV4J-cHdEE4nhfwJHOYv93tBXR5A9I,3314
6
+ databutton/experimental/folder/__init__.py,sha256=27dUyREJ-08xP4OmQUtAyWWz7_hWEat6ajqiJ2xgyeo,71
7
+ databutton/experimental/folder/folder.py,sha256=Qr-Uo-QITVADxh22Da635HXBRdHmkfb7vQMa4NMEYOA,1793
6
8
  databutton/internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
9
  databutton/internal/auth.py,sha256=MY4S7Gvb6xufmZ0SssZka0eY_18lJbxHW61cHrisnro,3182
8
10
  databutton/internal/byteutils.py,sha256=2SYQxhbK1Kj__u_ap01kPpeb1b_bcZAXSz6aqWwetUA,740
@@ -22,8 +24,8 @@ databutton/secrets/__init__.py,sha256=sI0okrfRBs2l5tcLTrKc9uUfPVVRMM9D7WED8p226t
22
24
  databutton/secrets/secrets.py,sha256=pehXsD09iKTxHaNQJ6awvIHXgRXBJrf4Xhrc11ZUeOk,3427
23
25
  databutton/storage/__init__.py,sha256=7ZNd4eQQ7lYYIe1MqCuFbFF1aAVCuj2c_zmJfaPVlDY,252
24
26
  databutton/storage/storage.py,sha256=x9LTyoAfLTWFCoy7XhA0tVUTkjldx8gYax09RkhMR1Q,20369
25
- databutton/version.py,sha256=x_sSQ6DyrwYBlVWTdMfU-aWaeILPwYZhKHci0vV4980,175
26
- databutton-0.37.9.dist-info/LICENSE,sha256=c7h4pcVZapFEmqWoRTRv_S1P_aibrtDobqmlR-QtMUk,45
27
- databutton-0.37.9.dist-info/METADATA,sha256=FX_Uz83TBRqzXjAz_nD23Uzd8XPD8UyCvdEbcnYLqhQ,2753
28
- databutton-0.37.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
29
- databutton-0.37.9.dist-info/RECORD,,
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,,