csc-cia-stne 0.0.70__py3-none-any.whl → 0.0.72__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.
@@ -175,39 +175,83 @@ class GoogleDrive:
175
175
 
176
176
  return {"success": False, "result": None, "error": str(e)}
177
177
 
178
- def create_folder(self, name: str, parent_folder_id: str):
178
+
179
+ def _validate_folder_existence(self, folder:str, id_folder:str):
180
+ """
181
+ Verifica a existência de uma pasta no Google Drive.
182
+ Args:
183
+ folder (str): O nome da pasta a ser verificada.
184
+ id_folder (str): O ID da pasta pai.
185
+ Returns:
186
+ dict or None: Um dicionário contendo as informações da pasta se ela existir, caso contrário, retorna None.
187
+ Raises:
188
+ ValueError: Se ocorrer algum erro durante a busca pela pasta.
189
+ """
190
+
191
+ query = f"'{id_folder}' in parents and trashed=false"
192
+
193
+ try:
194
+
195
+ response = self.service.files().list(q=query, spaces='drive', fields='nextPageToken, files(id, name, mimeType)', pageToken=None, includeItemsFromAllDrives = True, supportsAllDrives = True).execute()
196
+
197
+ items = response.get('files', [])
198
+
199
+ for item in items:
200
+
201
+ if item['mimeType'] == 'application/vnd.google-apps.folder' and item['name'] == folder:
202
+
203
+ return item
204
+
205
+ return None
206
+
207
+ except Exception as e:
208
+
209
+ raise ValueError(f'Erro tentando procurar pela pasta:{e}')
210
+
211
+
212
+ def create_folder(self, name: str, parent_folder_id: str, validate_existence:bool=False):
179
213
  """
180
214
  Cria uma pasta no Google Drive dentro de uma pasta existente.
181
215
 
182
216
  Args:
183
217
  name (str): Nome da pasta a ser criada.
184
218
  parent_folder_id (int): ID da pasta pai onde a nova pasta será criada.
185
-
219
+ validate_existence (bool): Se True, verifica se a pasta já existe antes de criá-la. Defaults to False.
186
220
  Returns:
187
221
  str: ID da pasta criada.
188
222
  """
189
223
  try:
190
- CreateFolderValidator(name=name, parent_folder_id=parent_folder_id)
224
+ CreateFolderValidator(name=name, parent_folder_id=parent_folder_id,validate_existence=validate_existence)
191
225
  except ValidationError as e:
192
226
  raise ValueError(
193
227
  "Erro na validação dos dados de input da inicialização da instância:",
194
228
  e.errors(),
195
229
  )
196
230
 
197
- try:
198
- folder_metadata = {
199
- "name": name,
200
- "parents": [parent_folder_id],
201
- "mimeType": "application/vnd.google-apps.folder",
202
- }
203
- folder = (
204
- self.service.files()
205
- .create(body=folder_metadata, fields="id", supportsAllDrives=True)
206
- .execute()
207
- )
208
- return {"success": True, "result": folder}
209
- except Exception as e:
210
- return {"success": False, "result": None, "error": str(e)}
231
+ status_existence = None
232
+
233
+ if validate_existence:
234
+
235
+ status_existence = self._validate_folder_existence(name, parent_folder_id)
236
+
237
+ if status_existence is None:
238
+
239
+ try:
240
+ folder_metadata = {
241
+ "name": name,
242
+ "parents": [parent_folder_id],
243
+ "mimeType": "application/vnd.google-apps.folder",
244
+ }
245
+ folder = (
246
+ self.service.files()
247
+ .create(body=folder_metadata, fields="id", supportsAllDrives=True)
248
+ .execute()
249
+ )
250
+ return {"success": True, "result": folder}
251
+ except Exception as e:
252
+ return {"success": False, "result": None, "error": str(e)}
253
+
254
+ return {"success": True, "result": status_existence}
211
255
 
212
256
  def list_items_folder(
213
257
  self,
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import platform
2
3
  from rich.logging import RichHandler
3
4
  from rich.theme import Theme
4
5
  from rich.console import Console
@@ -66,11 +67,19 @@ def get_logger(nome):
66
67
  def __init__(self, *args, rich_tracebacks=True, show_time=True, show_level=True, show_path=True, console=console, omit_repeated_times=True, **kwargs):
67
68
  super().__init__(rich_tracebacks=rich_tracebacks, show_time=show_time, log_time_format="%d/%m/%Y %H:%M:%S", show_level=show_level, show_path=show_path, console=console, omit_repeated_times=omit_repeated_times, *args, **kwargs)
68
69
  self.show_time = show_time
70
+ self.sistema_operacional = f"{platform.system()} {platform.release()}".upper()
69
71
 
72
+ def emit(self, record):
73
+ # Verifica se a variável global está definida e se o valor dela é 'SERVER'
74
+ if "SERVER" in self.sistema_operacional:
75
+ return # Não faz nada, impedindo a exibição do log
76
+
77
+ super().emit(record) # Caso contrário, processa normalmente
70
78
 
71
79
  def format(self, record: logging.LogRecord) -> str:
72
80
  try:
73
81
  msg = f"| {record.getMessage()}"
82
+ msg = msg.replace("\n", "\n| ")
74
83
  #msg = f"{record.getMessage()}"
75
84
 
76
85
  return(str(msg))
@@ -78,15 +87,6 @@ def get_logger(nome):
78
87
  print("FALHA AO FORMATAR O LOG")
79
88
  print(e)
80
89
 
81
- # Configurando o logging com o CustomRichHandler
82
- # Comentado pois estava gerando logs de libs como slack_sdk e big query
83
- # logging.basicConfig(
84
- # level=log_config_level,
85
- # handlers=[CustomRichHandler()],
86
- # datefmt="%d/%m/%Y %H:%M:%S |",
87
- # format="| %(message)s"
88
- # )
89
-
90
90
  def add_log_level(level_name, level_num, method_name=None):
91
91
  """
92
92
  Adiciona um log level
@@ -134,7 +134,6 @@ def get_logger(nome):
134
134
 
135
135
  # Sendo setado aqui pois no basicConfig estava gerando logs para as libs do slack_sdk e big query
136
136
 
137
- #logger.addHandler(CustomRichHandler())
138
137
  # Adiciona o CustomRichHandler se ainda não estiver presente
139
138
  if not any(isinstance(handler, CustomRichHandler) for handler in logger.handlers):
140
139
  logger.addHandler(CustomRichHandler())
@@ -69,6 +69,7 @@ class CreateFolderValidator(BaseModel):
69
69
  """
70
70
  name: str
71
71
  parent_folder_id: str
72
+ validate_existence: bool
72
73
 
73
74
  """
74
75
  Valida se o valor fornecido é uma string não vazia.
@@ -86,6 +87,12 @@ class CreateFolderValidator(BaseModel):
86
87
  raise ValueError(f"O campo '{info.field_name}' deve ser strings e não {type(value)}")
87
88
  return value
88
89
 
90
+ @field_validator('validate_existence')
91
+ def check_bool_input(cls, value, info):
92
+ if not isinstance(value, bool):
93
+ raise ValueError(f"O campo '{info.field_name}' deve ser bool e não {type(value)}")
94
+ return value
95
+
89
96
  class ListFolderValidator(BaseModel):
90
97
  """
91
98
  Validação para a classe ListFolderValidator.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: csc_cia_stne
3
- Version: 0.0.70
3
+ Version: 0.0.72
4
4
  Summary: Biblioteca do time CSC-CIA utilizada no desenvolvimento de RPAs
5
5
  License: MIT
6
6
  Keywords: karavela,csc,cia,stone,rpa,botcity,stne
@@ -3,10 +3,10 @@ csc_cia_stne/bc_correios.py,sha256=pQAnRrcXEMrx3N1MWydZVIhEQLerh3x8-0B045zZIzk,2
3
3
  csc_cia_stne/bc_sta.py,sha256=KWHTytM3msAFayt8y5_97RwWHE8Dv8ssfwyh6zU7xI0,25836
4
4
  csc_cia_stne/email.py,sha256=RK_TzWBVnUfpP-s5NvjTJJjzhICy8e2fME9EuaiySMY,8162
5
5
  csc_cia_stne/gcp_bigquery.py,sha256=jYxvqrWDOPkxc05U4aef7V5lL8ptqsE93lfn0dLFyvc,7385
6
- csc_cia_stne/google_drive.py,sha256=OeBIliKZUxSBcOQwBfAdaQMKChWVWaEudMUDuc1rjU4,14399
6
+ csc_cia_stne/google_drive.py,sha256=k6GnM8bxQUPbXhaK6Sa4JpWrCcJ0vzYgXP8Uexy7YR0,16073
7
7
  csc_cia_stne/karavela.py,sha256=jJCYX43D49gGuzmwwK6bN9XVnv2dXdp9iHnnV5H1LMQ,4794
8
8
  csc_cia_stne/logger_json.py,sha256=CXxSCOFGMymDi8XE9SKnPKjW4D0wJLqDLnxqePS26i8,3187
9
- csc_cia_stne/logger_rich.py,sha256=d6tL7f7Yldg3eivNWRiwRTwT0i5w68aeMRfrQoNRHVQ,5072
9
+ csc_cia_stne/logger_rich.py,sha256=fklgkBb4rblKQd7YZ3q-eWfhGg9eflO2k2-z4pGh_yo,5201
10
10
  csc_cia_stne/provio.py,sha256=G-pDnHYLSp97joc7S7dvwjNvl3omnTmvdi3rOPQf5GA,3987
11
11
  csc_cia_stne/servicenow.py,sha256=cJtNtLZ8glWfs3OAzl78ZFlPyPz39CSBxHqpTdUU7i0,32136
12
12
  csc_cia_stne/slack.py,sha256=33_UNF7M529eIuWjmzSJFEZ4RmVNkFkuVxvxwsKY1tQ,8126
@@ -22,12 +22,12 @@ csc_cia_stne/utilitarios/functions/func_recriar_pastas.py,sha256=4whZpB3aJQaCPJ3
22
22
  csc_cia_stne/utilitarios/functions/func_settings.py,sha256=XwlfqdcfocXQ8kTsDKZ6GsAtpzr0_u44AOTIMtdem7U,2059
23
23
  csc_cia_stne/utilitarios/functions/func_titulo.py,sha256=bH4tYxovTARF-g2kWUK_GIzzXt8egbVdp6mWD6fc_3I,5345
24
24
  csc_cia_stne/utilitarios/validations/GcpBigQueryValidator.py,sha256=PfCeeQquheZkrm07HTIjobleh3QQOjljRFGdxbQ1amQ,4630
25
- csc_cia_stne/utilitarios/validations/GoogleDriveValidator.py,sha256=PBo-AV2bjR__4o9jYxuXO-UyxjAZvVwYgMbtsrFK2sI,4537
25
+ csc_cia_stne/utilitarios/validations/GoogleDriveValidator.py,sha256=Q1oZTae4hDJ2TQ4sUL5Q5TkDNPoJo-DZQt6wIue2jwM,4811
26
26
  csc_cia_stne/utilitarios/validations/ServiceNowValidator.py,sha256=yleKUIo1ZfyloP9fDPNjv3JJXdLcocT81WIgRSYmqEA,14423
27
27
  csc_cia_stne/utilitarios/validations/__init__.py,sha256=O_qyEU2ji3u6LHUXZCXvUFsMpoMWL625qqHTXyXivTA,106
28
28
  csc_cia_stne/utilitarios/validations/web_validator.py,sha256=HYKYSpDv1RvRjZIuwTPt-AbEz-9392MxM_O329iYuSA,5722
29
- csc_cia_stne-0.0.70.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
30
- csc_cia_stne-0.0.70.dist-info/METADATA,sha256=_kgUcgPevyIlWDAk4umBHaXF98I7fUq3YBQneKMZVwQ,1340
31
- csc_cia_stne-0.0.70.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
32
- csc_cia_stne-0.0.70.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
33
- csc_cia_stne-0.0.70.dist-info/RECORD,,
29
+ csc_cia_stne-0.0.72.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
30
+ csc_cia_stne-0.0.72.dist-info/METADATA,sha256=YZJ6PX6IgGLTowSISxbxLQ6arllGlC_rNlb_XC4TKk4,1340
31
+ csc_cia_stne-0.0.72.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
32
+ csc_cia_stne-0.0.72.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
33
+ csc_cia_stne-0.0.72.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (76.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5