Skip to content

Commit 4aa9fb6

Browse files
committed
bump version to 0.2.2 and update error handling in SharePoint service
1 parent f40569a commit 4aa9fb6

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "office365-service"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Add your description here"
55
readme = "README.md"
66
authors = [
@@ -15,3 +15,6 @@ dependencies = [
1515
[build-system]
1616
requires = ["hatchling"]
1717
build-backend = "hatchling.build"
18+
19+
[tool.uv.sources]
20+
office365-rest-python-client = { git = "https://github.com/Dev4Mod/office365-rest-python-client.git" }

src/office365_service/sharepoint_service.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
from office365.sharepoint.client_context import ClientContext
88
from office365.sharepoint.files.file import File
99
from office365.sharepoint.folders.folder import Folder
10+
from office365.runtime.http.request_options import RequestOptions
1011

1112

12-
def handle_sharepoint_errors(max_retries: int = 5, delay_seconds: int = 3, timeout_seconds: int = 120):
13+
14+
def handle_sharepoint_errors(max_retries: int = 5, delay_seconds: int = 3):
1315
"""
1416
Decorador para tratar exceções de requisições do SharePoint, com lógica
1517
de nova autenticação, novas tentativas e controle de timeout.
1618
1719
Args:
1820
max_retries (int): Número máximo de tentativas para erros recuperáveis.
1921
delay_seconds (int): Atraso entre as tentativas.
20-
timeout_seconds (int): Tempo máximo de espera para a execução da operação em segundos.
2122
"""
2223

2324
def decorator(func):
@@ -87,7 +88,7 @@ def __init__(self, site_url: str, timeout_seconds: int = 90):
8788

8889
self.ctx.pending_request().beforeExecute += self._set_request_timeout
8990

90-
def _set_request_timeout(self, request_options):
91+
def _set_request_timeout(self, request_options: RequestOptions):
9192
"""
9293
Este método é chamado antes de cada requisição para injetar o parâmetro de timeout.
9394
"""
@@ -192,7 +193,6 @@ def criar_pasta(self, pasta_pai: Folder | str, nome_pasta: str):
192193
pasta = next((subpasta for subpasta in subpastas if nome_pasta in str(subpasta.name)), None)
193194
if pasta is not None:
194195
return pasta
195-
print("Criando pasta {0}...".format(nome_pasta))
196196
pasta = pasta_pai.folders.add(nome_pasta)
197197
pasta.execute_query()
198198
return pasta
@@ -207,7 +207,6 @@ def baixar_arquivo(self, arquivo_sp: File | str, caminho_download: str):
207207

208208
with open(caminho_download, "wb") as local_file:
209209
file_to_download.download_session(local_file).execute_query()
210-
print(f"Arquivo '{os.path.basename(str(arquivo_sp))}' baixado para '{caminho_download}'.")
211210

212211
@handle_sharepoint_errors()
213212
def enviar_arquivo(self, pasta_destino: Folder | str, arquivo_local: str, nome_arquivo_sp: str = None):
@@ -224,9 +223,7 @@ def enviar_arquivo(self, pasta_destino: Folder | str, arquivo_local: str, nome_a
224223
with open(arquivo_local, 'rb') as file_content:
225224
fbytes = file_content.read()
226225

227-
print(f"Enviando arquivo '{nome_arquivo_sp}'...")
228226
arquivo = pasta_destino.upload_file(nome_arquivo_sp, fbytes).execute_query()
229-
print(f"Arquivo '{nome_arquivo_sp}' enviado com sucesso!")
230227
return arquivo
231228

232229
@handle_sharepoint_errors()
@@ -238,8 +235,6 @@ def mover_arquivo(self, arquivo_origem: File, pasta_destino: Folder | str):
238235
raise FileNotFoundError(f"A pasta de destino '{pasta_destino}' não foi encontrada.")
239236
pasta_destino = pasta
240237

241-
print(f"Movendo '{arquivo_origem.name}' para '{pasta_destino.name}'...")
242-
243238
novo_arquivo = arquivo_origem.moveto(pasta_destino, flag=1)
244239
novo_arquivo.execute_query()
245240

@@ -254,18 +249,14 @@ def copiar_arquivo(self, arquivo_origem: File, pasta_destino: Folder | str):
254249
raise FileNotFoundError(f"A pasta de destino '{pasta_destino}' não foi encontrada.")
255250
pasta_destino = pasta
256251

257-
print(f"Copiando '{arquivo_origem.name}' para '{pasta_destino.name}'...")
258252
novo_arquivo = arquivo_origem.copyto(pasta_destino, True).execute_query()
259-
print("Arquivo copiado com sucesso.")
260253
return novo_arquivo
261254

262255
@handle_sharepoint_errors()
263256
def renomear_arquivo(self, arquivo: File, novo_nome: str) -> File:
264257
"""Renomeia um arquivo no SharePoint."""
265-
print(f"Renomeando '{arquivo.name}' para '{novo_nome}'...")
266258
novo_arquivo = arquivo.rename(novo_nome)
267259
novo_arquivo.execute_query()
268-
print("Arquivo renomeado com sucesso.")
269260
return novo_arquivo
270261

271262
@handle_sharepoint_errors()

0 commit comments

Comments
 (0)