Skip to content

Commit 5138e65

Browse files
committed
bump version to 0.2.5 and enhance file download with integrity check and retry logic
1 parent f23489f commit 5138e65

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "office365-service"
3-
version = "0.2.4"
3+
version = "0.2.5"
44
description = "Add your description here"
55
readme = "README.md"
66
authors = [

src/office365_service/sharepoint_service.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def criar_pasta(self, pasta_pai: Folder | str, nome_pasta: str):
203203
pasta.execute_query()
204204
return pasta
205205

206+
@handle_sharepoint_errors()
206207
def baixar_arquivo(self, arquivo_sp: File | str, caminho_download: str, max_tentativas: int = 3):
207208
"""
208209
Baixa um arquivo do SharePoint para um caminho local, com verificação de integridade e novas tentativas.
@@ -222,24 +223,20 @@ def baixar_arquivo(self, arquivo_sp: File | str, caminho_download: str, max_tent
222223
for tentativa in range(max_tentativas):
223224
print(f"Iniciando download de '{file_to_download.name}' (Tentativa {tentativa + 1}/{max_tentativas})...")
224225

225-
try:
226-
with open(caminho_download, "wb") as local_file:
227-
file_to_download.download_session(local_file).execute_query()
228-
229-
# Verificação do tamanho do arquivo
230-
tamanho_local = os.path.getsize(caminho_download)
226+
with open(caminho_download, "wb") as local_file:
227+
file_to_download.download(local_file).execute_query()
231228

232-
if tamanho_local == tamanho_remoto:
233-
print(
234-
f"Download de '{file_to_download.name}' concluído e verificado com sucesso. Tamanho: {tamanho_local} bytes.")
235-
return # Sucesso, sai da função
236-
else:
237-
print(f"Falha na verificação de tamanho para '{file_to_download.name}'.")
238-
print(f" -> Tamanho esperado: {tamanho_remoto} bytes")
239-
print(f" -> Tamanho baixado: {tamanho_local} bytes")
229+
# Verificação do tamanho do arquivo
230+
tamanho_local = os.path.getsize(caminho_download)
240231

241-
except Exception as e:
242-
print(f"Ocorreu um erro durante o download na tentativa {tentativa + 1}/{max_tentativas}: {e}")
232+
if tamanho_local == tamanho_remoto:
233+
print(
234+
f"Download de '{file_to_download.name}' concluído e verificado com sucesso. Tamanho: {tamanho_local} bytes.")
235+
return # Sucesso, sai da função
236+
else:
237+
print(f"Falha na verificação de tamanho para '{file_to_download.name}'.")
238+
print(f" -> Tamanho esperado: {tamanho_remoto} bytes")
239+
print(f" -> Tamanho baixado: {tamanho_local} bytes")
243240

244241
if tentativa < max_tentativas - 1:
245242
print("Aguardando 5 segundos para tentar novamente...")

0 commit comments

Comments
 (0)