sunholo 0.139.0__py3-none-any.whl → 0.139.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.
- sunholo/gcs/download_gcs_text.py +20 -2
- sunholo/gcs/metadata.py +34 -1
- {sunholo-0.139.0.dist-info → sunholo-0.139.1.dist-info}/METADATA +1 -1
- {sunholo-0.139.0.dist-info → sunholo-0.139.1.dist-info}/RECORD +8 -8
- {sunholo-0.139.0.dist-info → sunholo-0.139.1.dist-info}/WHEEL +0 -0
- {sunholo-0.139.0.dist-info → sunholo-0.139.1.dist-info}/entry_points.txt +0 -0
- {sunholo-0.139.0.dist-info → sunholo-0.139.1.dist-info}/licenses/LICENSE.txt +0 -0
- {sunholo-0.139.0.dist-info → sunholo-0.139.1.dist-info}/top_level.txt +0 -0
sunholo/gcs/download_gcs_text.py
CHANGED
@@ -3,12 +3,21 @@ import json
|
|
3
3
|
|
4
4
|
from ..custom_logging import log
|
5
5
|
from ..utils.mime import get_mime_type_gemini
|
6
|
+
from .metadata import check_gcs_file_size
|
6
7
|
from .download_url import get_bytes_from_gcs
|
7
8
|
|
8
|
-
def download_gcs_source_to_string(source:str) -> str:
|
9
|
+
def download_gcs_source_to_string(source:str, max_size_bytes: int = 1024*1024) -> str:
|
9
10
|
"""
|
10
|
-
|
11
|
+
Download a file from Google Cloud Storage and convert it to a string.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
source: str The Google Cloud Storage URI of the file to download (e.g., 'gs://bucket_name/file_name').
|
15
|
+
max_size_bytes: int Maximum file size to download, defaults to 1MB (1024*1024 bytes)
|
16
|
+
|
17
|
+
Returns:
|
18
|
+
str: The contents of the file as a string, or an empty string if the file could not be downloaded.
|
11
19
|
"""
|
20
|
+
|
12
21
|
mime_type = get_mime_type_gemini(source)
|
13
22
|
if mime_type == "":
|
14
23
|
log.warning(f"Can not download to string file source {source}")
|
@@ -52,6 +61,15 @@ def download_gcs_source_to_string(source:str) -> str:
|
|
52
61
|
|
53
62
|
try:
|
54
63
|
log.info(f"Extracting text for {source}")
|
64
|
+
# Check file size before downloading
|
65
|
+
file_size = check_gcs_file_size(source)
|
66
|
+
if file_size == -1:
|
67
|
+
log.warning(f"Could not determine file size for {source}")
|
68
|
+
return ""
|
69
|
+
elif file_size > max_size_bytes:
|
70
|
+
log.warning(f"File size {file_size} bytes exceeds maximum size limit of {max_size_bytes} bytes for {source}")
|
71
|
+
return ""
|
72
|
+
|
55
73
|
bytes = get_bytes_from_gcs(source)
|
56
74
|
string = bytes.decode('utf-8', errors='replace')
|
57
75
|
log.info(f"Extracted {len(string)} characters from {source}: {string[:100]}")
|
sunholo/gcs/metadata.py
CHANGED
@@ -30,4 +30,37 @@ def get_object_metadata(bucket_name, object_name):
|
|
30
30
|
custom_metadata = blob.metadata
|
31
31
|
|
32
32
|
log.info(f"Custom Metadata for {object_name}: {custom_metadata}")
|
33
|
-
return custom_metadata
|
33
|
+
return custom_metadata
|
34
|
+
|
35
|
+
def check_gcs_file_size(source: str) -> int:
|
36
|
+
"""
|
37
|
+
Check the size of a file in Google Cloud Storage without downloading the entire file.
|
38
|
+
|
39
|
+
Args:
|
40
|
+
source: str The Google Cloud Storage URI of the file to check (e.g., 'gs://bucket_name/file_name').
|
41
|
+
|
42
|
+
Returns:
|
43
|
+
int: The size of the file in bytes, or -1 if the size cannot be determined.
|
44
|
+
"""
|
45
|
+
from google.cloud import storage
|
46
|
+
|
47
|
+
try:
|
48
|
+
# Parse the GCS URI
|
49
|
+
if not source.startswith('gs://'):
|
50
|
+
log.warning(f"Invalid GCS URI format: {source}")
|
51
|
+
return -1
|
52
|
+
|
53
|
+
bucket_name, blob_path = source[5:].split('/', 1)
|
54
|
+
|
55
|
+
# Create a client and get the bucket
|
56
|
+
storage_client = storage.Client()
|
57
|
+
bucket = storage_client.bucket(bucket_name)
|
58
|
+
|
59
|
+
# Get the blob (file) and retrieve its metadata
|
60
|
+
blob = bucket.blob(blob_path)
|
61
|
+
blob.reload() # Fetch the latest metadata
|
62
|
+
|
63
|
+
return blob.size
|
64
|
+
except Exception as err:
|
65
|
+
log.error(f"Error checking file size for {source}: {str(err)}")
|
66
|
+
return -1
|
@@ -85,10 +85,10 @@ sunholo/excel/plugin.py,sha256=TJJdcKWyqEIce1agCJImvqvNp2CvLhzi4wUmLYHcLc8,4032
|
|
85
85
|
sunholo/gcs/__init__.py,sha256=SZvbsMFDko40sIRHTHppA37IijvJTae54vrhooEF5-4,90
|
86
86
|
sunholo/gcs/add_file.py,sha256=Pd5Zc1a3gqbuBgSI-UDC2mQnYGLJbAh_-IUzkDN5s9k,8273
|
87
87
|
sunholo/gcs/download_folder.py,sha256=ijJTnS595JqZhBH8iHFErQilMbkuKgL-bnTCMLGuvlA,1614
|
88
|
-
sunholo/gcs/download_gcs_text.py,sha256=
|
88
|
+
sunholo/gcs/download_gcs_text.py,sha256=apopEBxC6OT0KBwnlFOeNOXyiY4A8BKEVixzb1wgQrk,5583
|
89
89
|
sunholo/gcs/download_url.py,sha256=9QMEtZhrN-y1VAqvi-7Tw2GI9iRG_uuZzCg6Qhq8_yw,6421
|
90
90
|
sunholo/gcs/extract_and_sign.py,sha256=paRrTCvCN5vkQwCB7OSkxWi-pfOgOtZ0bwdXE08c3Ps,1546
|
91
|
-
sunholo/gcs/metadata.py,sha256=
|
91
|
+
sunholo/gcs/metadata.py,sha256=GEDxb_B_teNPGd6chPzQrK9df78R_kytKfthIlKPwKQ,2010
|
92
92
|
sunholo/genai/__init__.py,sha256=TV3PYHWoR4cChdmCOaYB0PtAEQ86qol9XYYEtb1JmSA,239
|
93
93
|
sunholo/genai/file_handling.py,sha256=JUFTlSnrxqKR3hczduyMiZ234UaSqiBdMOYpY2v4TYA,13720
|
94
94
|
sunholo/genai/genaiv2.py,sha256=uqWcfvlsPVPyQo-W_cP9h2TTzyYfzj4lyJlyqPyKTkI,20269
|
@@ -169,9 +169,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
|
|
169
169
|
sunholo/vertex/memory_tools.py,sha256=tBZxqVZ4InTmdBvLlOYwoSEWu4-kGquc-gxDwZCC4FA,7667
|
170
170
|
sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
|
171
171
|
sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
|
172
|
-
sunholo-0.139.
|
173
|
-
sunholo-0.139.
|
174
|
-
sunholo-0.139.
|
175
|
-
sunholo-0.139.
|
176
|
-
sunholo-0.139.
|
177
|
-
sunholo-0.139.
|
172
|
+
sunholo-0.139.1.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
|
173
|
+
sunholo-0.139.1.dist-info/METADATA,sha256=vOG7X6ZpBgF3og9_BNDil-Loy2tAW38orcqYo3ObTTk,10067
|
174
|
+
sunholo-0.139.1.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
175
|
+
sunholo-0.139.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
|
176
|
+
sunholo-0.139.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
|
177
|
+
sunholo-0.139.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|