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.
@@ -1,44 +1,47 @@
1
- import io
2
- import os
3
- import zipfile
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
- zip_bytes = io.BytesIO() # Use BytesIO as a buffer
11
- with zipfile.ZipFile(zip_bytes, "w", zipfile.ZIP_DEFLATED) as zipf:
12
- for root, _, files in os.walk(folder_path):
13
- for file in files:
14
- file_path = os.path.join(root, file)
15
- zipf.write(
16
- file_path,
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
- # Ensure the extraction path exists
26
- os.makedirs(extract_path, exist_ok=True)
27
- zip_bytes = io.BytesIO(bytes_data)
28
- with zipfile.ZipFile(zip_bytes, "r") as zip_ref:
29
- zip_ref.extractall(extract_path)
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
- zipped_bytes = zip_folder_to_bytes(folder_path)
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
- # Ensure the target folder exists before extraction
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
@@ -5,4 +5,4 @@ This module contains project version information.
5
5
  .. moduleauthor:: Databutton <support@databutton.com>
6
6
  """
7
7
 
8
- __version__ = "0.38.0"
8
+ __version__ = "0.38.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: databutton
3
- Version: 0.38.0
3
+ Version: 0.38.1
4
4
  Summary: The CLI for databutton.com
5
5
  License: Databutton
6
6
  Author: Databutton
@@ -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=LjzUZiE4nbvk2164s0dKY-hssCuJz5rWdUSsiw-rmRA,1548
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=nxbdNEKRX8YnlQvq3y9BsGGdJQZVOcowtLGPv4Q6zrw,175
28
- databutton-0.38.0.dist-info/LICENSE,sha256=c7h4pcVZapFEmqWoRTRv_S1P_aibrtDobqmlR-QtMUk,45
29
- databutton-0.38.0.dist-info/METADATA,sha256=30xJ0gxIGDrkcAq-m4lHtEE5YWrSc6Hch6DaDeO_nwU,2753
30
- databutton-0.38.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
31
- databutton-0.38.0.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,,