7
7
from office365 .sharepoint .client_context import ClientContext
8
8
from office365 .sharepoint .files .file import File
9
9
from office365 .sharepoint .folders .folder import Folder
10
+ from office365 .runtime .http .request_options import RequestOptions
10
11
11
12
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 ):
13
15
"""
14
16
Decorador para tratar exceções de requisições do SharePoint, com lógica
15
17
de nova autenticação, novas tentativas e controle de timeout.
16
18
17
19
Args:
18
20
max_retries (int): Número máximo de tentativas para erros recuperáveis.
19
21
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.
21
22
"""
22
23
23
24
def decorator (func ):
@@ -87,7 +88,7 @@ def __init__(self, site_url: str, timeout_seconds: int = 90):
87
88
88
89
self .ctx .pending_request ().beforeExecute += self ._set_request_timeout
89
90
90
- def _set_request_timeout (self , request_options ):
91
+ def _set_request_timeout (self , request_options : RequestOptions ):
91
92
"""
92
93
Este método é chamado antes de cada requisição para injetar o parâmetro de timeout.
93
94
"""
@@ -192,7 +193,6 @@ def criar_pasta(self, pasta_pai: Folder | str, nome_pasta: str):
192
193
pasta = next ((subpasta for subpasta in subpastas if nome_pasta in str (subpasta .name )), None )
193
194
if pasta is not None :
194
195
return pasta
195
- print ("Criando pasta {0}..." .format (nome_pasta ))
196
196
pasta = pasta_pai .folders .add (nome_pasta )
197
197
pasta .execute_query ()
198
198
return pasta
@@ -207,7 +207,6 @@ def baixar_arquivo(self, arquivo_sp: File | str, caminho_download: str):
207
207
208
208
with open (caminho_download , "wb" ) as local_file :
209
209
file_to_download .download_session (local_file ).execute_query ()
210
- print (f"Arquivo '{ os .path .basename (str (arquivo_sp ))} ' baixado para '{ caminho_download } '." )
211
210
212
211
@handle_sharepoint_errors ()
213
212
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
224
223
with open (arquivo_local , 'rb' ) as file_content :
225
224
fbytes = file_content .read ()
226
225
227
- print (f"Enviando arquivo '{ nome_arquivo_sp } '..." )
228
226
arquivo = pasta_destino .upload_file (nome_arquivo_sp , fbytes ).execute_query ()
229
- print (f"Arquivo '{ nome_arquivo_sp } ' enviado com sucesso!" )
230
227
return arquivo
231
228
232
229
@handle_sharepoint_errors ()
@@ -238,8 +235,6 @@ def mover_arquivo(self, arquivo_origem: File, pasta_destino: Folder | str):
238
235
raise FileNotFoundError (f"A pasta de destino '{ pasta_destino } ' não foi encontrada." )
239
236
pasta_destino = pasta
240
237
241
- print (f"Movendo '{ arquivo_origem .name } ' para '{ pasta_destino .name } '..." )
242
-
243
238
novo_arquivo = arquivo_origem .moveto (pasta_destino , flag = 1 )
244
239
novo_arquivo .execute_query ()
245
240
@@ -254,18 +249,14 @@ def copiar_arquivo(self, arquivo_origem: File, pasta_destino: Folder | str):
254
249
raise FileNotFoundError (f"A pasta de destino '{ pasta_destino } ' não foi encontrada." )
255
250
pasta_destino = pasta
256
251
257
- print (f"Copiando '{ arquivo_origem .name } ' para '{ pasta_destino .name } '..." )
258
252
novo_arquivo = arquivo_origem .copyto (pasta_destino , True ).execute_query ()
259
- print ("Arquivo copiado com sucesso." )
260
253
return novo_arquivo
261
254
262
255
@handle_sharepoint_errors ()
263
256
def renomear_arquivo (self , arquivo : File , novo_nome : str ) -> File :
264
257
"""Renomeia um arquivo no SharePoint."""
265
- print (f"Renomeando '{ arquivo .name } ' para '{ novo_nome } '..." )
266
258
novo_arquivo = arquivo .rename (novo_nome )
267
259
novo_arquivo .execute_query ()
268
- print ("Arquivo renomeado com sucesso." )
269
260
return novo_arquivo
270
261
271
262
@handle_sharepoint_errors ()
0 commit comments