rpa-suite 1.3.3__py3-none-any.whl → 1.3.5__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.
Files changed (48) hide show
  1. rpa_suite/__init__.py +4 -1
  2. rpa_suite/core/__init__.py +1 -0
  3. rpa_suite/core/clock.py +271 -0
  4. rpa_suite/core/date.py +138 -0
  5. rpa_suite/core/dir.py +182 -0
  6. rpa_suite/core/email.py +343 -0
  7. rpa_suite/core/file.py +209 -0
  8. rpa_suite/core/log.py +304 -0
  9. rpa_suite/core/print.py +197 -0
  10. rpa_suite/core/regex.py +62 -0
  11. rpa_suite/core/validate.py +220 -0
  12. rpa_suite/{log → functions}/__create_log_dir.py +5 -7
  13. rpa_suite/{file → functions}/__create_ss_dir.py +2 -2
  14. rpa_suite/functions/__init__.py +1 -0
  15. rpa_suite/{log → functions}/_functions_logger.py +8 -8
  16. rpa_suite/{log → functions}/_logger.py +3 -3
  17. rpa_suite/suite.py +238 -148
  18. {rpa_suite-1.3.3.dist-info → rpa_suite-1.3.5.dist-info}/METADATA +66 -55
  19. rpa_suite-1.3.5.dist-info/RECORD +25 -0
  20. rpa_suite/clock/__init__.py +0 -1
  21. rpa_suite/clock/exec_at.py +0 -133
  22. rpa_suite/clock/scheduler.py +0 -38
  23. rpa_suite/clock/waiter.py +0 -139
  24. rpa_suite/date/__init__.py +0 -1
  25. rpa_suite/date/date.py +0 -124
  26. rpa_suite/email/__init__.py +0 -1
  27. rpa_suite/email/sender_smtp.py +0 -203
  28. rpa_suite/file/__init__.py +0 -1
  29. rpa_suite/file/counter.py +0 -69
  30. rpa_suite/file/file_flag.py +0 -103
  31. rpa_suite/file/screen_shot.py +0 -91
  32. rpa_suite/file/temp_dir.py +0 -176
  33. rpa_suite/log/__init__.py +0 -1
  34. rpa_suite/log/functions_logger_uru.py +0 -172
  35. rpa_suite/log/log_decorator.py +0 -37
  36. rpa_suite/log/logger_uru.py +0 -110
  37. rpa_suite/regex/__init__.py +0 -1
  38. rpa_suite/regex/pattern_in_text.py +0 -58
  39. rpa_suite/validate/__init__.py +0 -1
  40. rpa_suite/validate/mail_validator.py +0 -93
  41. rpa_suite/validate/string_validator.py +0 -120
  42. rpa_suite-1.3.3.dist-info/RECORD +0 -36
  43. /rpa_suite/{log/printer.py → functions/_printer.py} +0 -0
  44. /rpa_suite/{log → functions}/_variables.py +0 -0
  45. /rpa_suite/{log → functions}/_variables_uru.py +0 -0
  46. {rpa_suite-1.3.3.dist-info → rpa_suite-1.3.5.dist-info}/WHEEL +0 -0
  47. {rpa_suite-1.3.3.dist-info → rpa_suite-1.3.5.dist-info}/licenses/LICENSE +0 -0
  48. {rpa_suite-1.3.3.dist-info → rpa_suite-1.3.5.dist-info}/top_level.txt +0 -0
rpa_suite/file/counter.py DELETED
@@ -1,69 +0,0 @@
1
- # /counter.py
2
-
3
- import os
4
- from typing import Dict, List, Union
5
- from rpa_suite.log.printer import error_print, success_print
6
-
7
-
8
- def count_files(
9
- dir_to_count: List[str] = ['.'],
10
- type_extension: str = '*',
11
- display_message: bool = False,
12
- ) -> Dict[str, Union[bool, int]]:
13
-
14
- """
15
- Function responsible for counting files within a folder, considers subfolders to do the count, searches by file type, being all files by default. \n
16
-
17
- Parameters:
18
- ----------
19
- ``dir_to_count: list`` - should be a list, accepts more than one path to count files.
20
- ``type_extension: str`` - should be a string with the format/extension of the type of file you want to be searched for counting, if empty by default will be used ``*`` which will count all files.
21
-
22
- Return:
23
- ----------
24
- >>> type:dict
25
- * 'success': bool - represents if the action was performed successfully
26
- * 'qt': int - number that represents the quantity of files that were counted
27
-
28
- Description: pt-br
29
- ----------
30
- Função responsavel por fazer a contagem de arquivos dentro de uma pasta, considera subpastas para fazer a contagem, busca por tipo de arquivo, sendo todos arquivos por default. \n
31
-
32
- Parametros:
33
- ----------
34
- ``dir_to_count: list`` - deve ser uma lista, aceita mais de um caminho para contar arquivos.
35
- ``type_extension: str`` - deve ser uma string com o formato/extensão do tipo de arquivo que deseja ser buscado para contagem, se vazio por default sera usado ``*`` que contará todos arquivos.
36
-
37
- Retorno:
38
- ----------
39
- >>> type:dict
40
- * 'success': bool - representa se ação foi realizada com sucesso
41
- * 'qt': int - numero que representa a quantidade de arquivos que foram contados
42
- """
43
-
44
-
45
- # Local Variables
46
- result: dict = {
47
- 'success': False,
48
- 'qt': 0
49
- }
50
-
51
-
52
- # Process
53
- try:
54
- for dir in dir_to_count:
55
- for current_dir, sub_dir, files in os.walk(dir):
56
- for file in files:
57
- if type_extension == '*' or file.endswith(f'.{type_extension}'):
58
- result['qt'] += 1
59
- result['success'] = True
60
-
61
- if display_message:
62
- success_print(f'Function: {count_files.__name__} counted {result["qt"]} files.')
63
-
64
- except Exception as e:
65
- result['success'] = False
66
- error_print(f'Error when trying to count files! Error: {str(e)}')
67
-
68
- finally:
69
- return result
@@ -1,103 +0,0 @@
1
- # /file_flag.py
2
-
3
- import os, time
4
- from rpa_suite import suite as rpa
5
-
6
-
7
- def file_flag_create(display_message: bool = True, path_to_create: str = None, name_file: str = 'running.flag') -> None:
8
- """
9
- Function responsible for create a file flag on root directory by default. Path, name file and display message was optional. \n
10
-
11
- Parameters:
12
- ----------
13
- ``display_message: bool`` - should be boolean, True prints message on console.
14
- ``path_to_create: str`` - should be a string, by default use root dir with "os.getcwd()".
15
- ``name_file: str`` - should be a string, by default "running.flag".
16
-
17
- Return:
18
- ----------
19
- >>> type:bool
20
- * 'bool' - represents the result of performance this action
21
-
22
- Description: pt-br
23
- ----------
24
- Função responsável por criar um arquivo de flag na raiz do projeto por padrão. O diretório, o nome do arquivo e a possibilidade de imprimir no console a mensagem de sucesso, são opcionais.
25
-
26
- Parâmetros:
27
- ----------
28
- ``display_message: bool`` - deve ser booleano, True para o caso de imprimir no console a mensagem de resultado.
29
- ``path_to_create: str`` - deve ser string, por padrão usa como raiz do projeto o comando "os.getcwd()".
30
- ``name_file: str`` - deve ser string, por padrão "running.flag".
31
-
32
- Retorno:
33
- ----------
34
- >>> tipo: bool
35
- * 'bool' - representa o resultado performado da ação
36
- """
37
-
38
- try:
39
- if path_to_create == None:
40
- path_origin: str = os.getcwd()
41
- full_path_with_name = fr'{path_origin}/{name_file}'
42
- else:
43
- full_path_with_name = fr'{path_to_create}/{name_file}'
44
-
45
- with open(full_path_with_name, 'w', encoding='utf-8') as file:
46
- file.write('[T-BOT Crédit Simulation] running in realtime, waiting finish to new execution')
47
-
48
- if display_message: rpa.success_print("Flag file created.")
49
- return True
50
-
51
- except Exception as e:
52
- rpa.error_print(f'Erro na função file_scheduling_create: {str(e)}')
53
- return False
54
-
55
-
56
- def file_flag_delete(display_message: bool = True, path_to_delete: str = None, name_file: str = 'running.flag') -> None:
57
- """
58
- Function responsible for delete a file flag on root directory by default. Path, name file and display message was optional. \n
59
-
60
- Parameters:
61
- ----------
62
- ``display_message: bool`` - should be boolean, True prints message on console.
63
- ``path_to_delete: str`` - should be a string, by default use root dir with "os.getcwd()".
64
- ``name_file: str`` - should be a string, by default "running.flag".
65
-
66
- Return:
67
- ----------
68
- >>> type:bool
69
- * 'bool' - represents the result of performance this action
70
-
71
- Description: pt-br
72
- ----------
73
- Função responsável por deletar um arquivo de flag na raiz do projeto por padrão. O diretório, o nome do arquivo e a possibilidade de imprimir no console a mensagem de sucesso, são opcionais.
74
-
75
- Parâmetros:
76
- ----------
77
- ``display_message: bool`` - deve ser booleano, True para o caso de imprimir no console a mensagem de resultado.
78
- ``path_to_delete: str`` - deve ser string, por padrão usa como raiz do projeto o comando "os.getcwd()".
79
- ``name_file: str`` - deve ser string, por padrão "running.flag".
80
-
81
- Retorno:
82
- ----------
83
- >>> tipo: bool
84
- * 'bool' - representa o resultado performado da ação
85
- """
86
-
87
- try:
88
-
89
- if path_to_delete == None:
90
- path_origin: str = os.getcwd()
91
- full_path_with_name = fr'{path_origin}/{name_file}'
92
- else:
93
- full_path_with_name = fr'{path_to_delete}/{name_file}'
94
-
95
- if os.path.exists(full_path_with_name):
96
- os.remove(full_path_with_name)
97
- if display_message: print("Flag file deleted.")
98
- else:
99
- rpa.alert_print("Flag file not found.")
100
-
101
- except Exception as e:
102
- rpa.error_print(f'Erro na função file_scheduling_delete: {str(e)}')
103
- time.sleep(1)
@@ -1,91 +0,0 @@
1
- # /screen_shot.py
2
-
3
- import os, time
4
- from datetime import datetime
5
- from rpa_suite.log.printer import error_print, success_print
6
- from .__create_ss_dir import __create_ss_dir
7
- from colorama import Fore
8
-
9
-
10
-
11
- def screen_shot(path_dir:str = None, file_name: str = 'screenshot', save_with_date: bool = True, delay: int = 1, use_default_path_and_name: bool = True, name_ss_dir:str = None, display_message: bool = False) -> str | None:
12
-
13
- """
14
- Function responsible for create a dir for screenshot, and file screenshot and save this in dir to create, if dir exists save it on original dir. By default uses date on file name. \n
15
-
16
- Parameters:
17
- ----------
18
- ``file_path: str`` - should be a string, not have a default path.
19
- ``file_name: str`` - should be a string, by default name is `screenshot`.
20
- ``save_with_date: bool`` - should be a boolean, by default `True` save namefile with date `foo_dd_mm_yyyy-hh_mm_ss.png`.
21
- ``delay: int`` - should be a int, by default 1 (represents seconds).
22
-
23
- Return:
24
- ----------
25
- >>> type:str
26
- * 'screenshot_path': str - represents the absulute path created for this file
27
-
28
- Description: pt-br
29
- ----------
30
- Função responsável por criar um diretório para captura de tela, e arquivo de captura de tela e salvar isso no diretório a ser criado, se o diretório existir, salve-o no diretório original. Por padrão, usa a data no nome do arquivo.
31
-
32
- Parâmetros:
33
- ----------
34
- ``file_path: str`` - deve ser uma string, não tem um caminho padrão.
35
- ``file_name: str`` - deve ser uma string, por padrão o nome é `screenshot`.
36
- ``save_with_date: bool`` - deve ser um booleano, por padrão `True` salva o nome do arquivo com a data `foo_dd_mm_yyyy-hh_mm_ss.png`.
37
- ``delay: int`` - deve ser um int, por padrão 1 representado em segundo(s).
38
-
39
- Retorno:
40
- ----------
41
- >>> tipo: str
42
- * 'screenshot_path': str - representa o caminho absoluto do arquivo criado
43
- """
44
-
45
- # proccess
46
- try:
47
-
48
- try:
49
- import pyautogui
50
- import pyscreeze
51
-
52
- except ImportError:
53
- raise ImportError(f"\nThe libraries ‘pyautogui’ and ‘Pillow’ are necessary to use this module. {Fore.YELLOW}Please install them with: ‘pip install pyautogui pillow‘{Fore.WHITE}")
54
-
55
- time.sleep(delay)
56
-
57
- if not use_default_path_and_name:
58
- result_tryed: dict = __create_ss_dir(path_dir, name_ss_dir)
59
- path_dir = result_tryed['path_created']
60
- else:
61
- if path_dir == None and name_ss_dir == None:
62
- result_tryed: dict = __create_ss_dir()
63
- path_dir = result_tryed['path_created']
64
-
65
-
66
- if save_with_date: # use date on file name
67
- image = pyautogui.screenshot()
68
- file_name = f'{file_name}_{datetime.today().strftime("%d_%m_%Y-%H_%M_%S")}.png'
69
- path_file_screenshoted = os.path.join(path_dir, file_name)
70
-
71
- image.save(path_file_screenshoted)
72
- if display_message:
73
- success_print(path_file_screenshoted)
74
-
75
- return path_file_screenshoted
76
-
77
- else: # not use date on file name
78
- image = pyautogui.screenshot()
79
- file_name = f'{file_name}.png'
80
- path_file_screenshoted = os.path.join(path_dir, file_name)
81
-
82
- image.save(path_file_screenshoted)
83
- if display_message:
84
- success_print(path_file_screenshoted)
85
-
86
- return path_file_screenshoted
87
-
88
- except Exception as e:
89
-
90
- error_print(f'Error to execute function:{screen_shot.__name__}! Error: {str(e)}')
91
- return None
@@ -1,176 +0,0 @@
1
- # /temp_dir.py
2
-
3
- import os, shutil
4
- from typing import Union
5
- from rpa_suite.log.printer import error_print, alert_print, success_print
6
-
7
-
8
- def create_temp_dir(path_to_create: str = 'default', name_temp_dir: str='temp', display_message: bool = False) -> dict[str, Union[bool, str, None]]:
9
-
10
- """
11
- Function responsible for creating a temporary directory to work with files and etc. \n
12
-
13
- Parameters:
14
- ----------
15
- ``path_to_create: str`` - should be a string with the full path pointing to the folder where the temporary folder should be created, if it is empty the ``default`` value will be used which will create a folder in the current directory where the file containing this function was called.
16
-
17
- ``name_temp_dir: str`` - should be a string representing the name of the temporary directory to be created. If it is empty, the ``temp`` value will be used as the default directory name.
18
-
19
- Return:
20
- ----------
21
- >>> type:dict
22
- * 'success': bool - represents case the action was performed successfully
23
- * 'path_created': str - path of the directory that was created on the process
24
-
25
- Description: pt-br
26
- ----------
27
- Função responsavel por criar diretório temporário para trabalhar com arquivos e etc. \n
28
-
29
- Parametros:
30
- ----------
31
- ``path_to_create: str`` - deve ser uma string com o path completo apontando para a pasta onde deve ser criada a pasta temporaria, se estiver vazio sera usado valor ``default`` que criará pasta no diretório atual onde o arquivo contendo esta função foi chamada.
32
-
33
- ``name_temp_dir: str`` - deve ser uma string representando o nome do diretório temporário a ser criado. Se estiver vazio, o valor ``temp`` será usado como o nome padrão do diretório.
34
-
35
- Retorno:
36
- ----------
37
- >>> type:dict
38
- * 'success': bool - representa se ação foi realizada com sucesso
39
- * 'path_created': str - path do diretório que foi criado no processo
40
- """
41
-
42
- # Local Variables
43
- result: dict = {
44
- 'success': bool,
45
- 'path_created': str,
46
- }
47
-
48
- try:
49
- # by 'default', defines path to local script execution path
50
- if path_to_create == 'default':
51
- path_to_create: str = os.getcwd()
52
-
53
- # Build path to new dir
54
- full_path: str = os.path.join(path_to_create, name_temp_dir)
55
-
56
- # Create dir in this block
57
- try:
58
-
59
- # Successefully created
60
- os.makedirs(full_path, exist_ok=False)
61
-
62
- result['success'] = True
63
- result['path_created'] = fr'{full_path}'
64
-
65
- if display_message:
66
- success_print(f"Dir:'{full_path}' Created!")
67
-
68
- except FileExistsError:
69
- result['success'] = False
70
- result['path_created'] = None
71
- alert_print(f"Dir:'{full_path}' already exists.")
72
-
73
- except PermissionError:
74
- result['success'] = False
75
- result['path_created'] = None
76
- alert_print(f"Permission Denied: Not Able to create dir:'{full_path}'.")
77
-
78
- except Exception as e:
79
- result['success'] = False
80
- result['path_created'] = None
81
- error_print(f'Error capturing current path to create temporary directory! Error: {str(e)}')
82
-
83
- finally:
84
- return result
85
-
86
-
87
- def delete_temp_dir(path_to_delete: str = 'default', name_temp_dir: str='temp', delete_files: bool = False, display_message: bool = False) -> dict[str, Union[bool, str, None]]:
88
-
89
- """
90
- Function responsible for deleting a temporary directory. \n
91
-
92
- Parameters:
93
- ----------
94
- ``path_to_delete: str`` - should be a string with the full path pointing to the folder where the temporary folder should be deleted, if it is empty the ``default`` value will be used which will delete a folder in the current directory where the file containing this function was called.
95
-
96
- ``name_temp_dir: str`` - should be a string representing the name of the temporary directory to be deleted. If it is empty, the ``temp`` value will be used as the default directory name.
97
-
98
- ``delete_files: bool`` - should be a boolean indicating whether to delete files in the directory. If it is False, files in the directory will not be deleted.
99
-
100
- Return:
101
- ----------
102
- >>> type:dict
103
- * 'success': bool - represents case the action was performed successfully
104
- * 'path_deleted': str - path of the directory that was deleted on the process
105
-
106
- Description: pt-br
107
- ----------
108
- Função responsavel por deletar diretório temporário. \n
109
-
110
- Parametros:
111
- ----------
112
- ``path_to_delete: str`` - deve ser uma string com o path completo apontando para a pasta onde deve ser deletada a pasta temporaria, se estiver vazio sera usado valor ``default`` que deletará pasta no diretório atual onde o arquivo contendo esta função foi chamada.
113
-
114
- ``name_temp_dir: str`` - deve ser uma string representando o nome do diretório temporário a ser deletado. Se estiver vazio, o valor ``temp`` será usado como o nome padrão do diretório.
115
-
116
- ``delete_files: bool`` - deve ser um booleano indicando se deve deletar arquivos no diretório. Se for False, arquivos no diretório não serão deletados.
117
-
118
- Retorno:
119
- ----------
120
- >>> type:dict
121
- * 'success': bool - representa se ação foi realizada com sucesso
122
- * 'path_deleted': str - path do diretório que foi deletado no processo
123
- """
124
-
125
- # Local Variables
126
- result: dict = {
127
- 'success': bool,
128
- 'path_deleted': str,
129
- }
130
-
131
- try:
132
- # by 'default', defines path to local script execution path
133
- if path_to_delete == 'default':
134
- path_to_delete: str = os.getcwd()
135
-
136
- # Build path to new dir
137
- full_path: str = os.path.join(path_to_delete, name_temp_dir)
138
-
139
- # Delete dir in this block
140
- try:
141
-
142
- # Check if directory exists
143
- if os.path.exists(full_path):
144
-
145
- # Check if delete_files is True
146
- if delete_files:
147
- # Delete all files in the directory
148
- shutil.rmtree(full_path)
149
-
150
- else:
151
- # Delete the directory only
152
- os.rmdir(full_path)
153
-
154
- result['success'] = True
155
- result['path_deleted'] = fr'{full_path}'
156
-
157
- if display_message:
158
- success_print(f"Dir:'{full_path}' Deleted!")
159
-
160
- else:
161
- result['success'] = False
162
- result['path_deleted'] = None
163
- alert_print(f"Dir:'{full_path}' Don't exists.")
164
-
165
- except PermissionError:
166
- result['success'] = False
167
- result['path_deleted'] = None
168
- alert_print(f"Permission Denied: Not Able to delete dir: '{full_path}'.")
169
-
170
- except Exception as e:
171
- result['success'] = False
172
- result['path_deleted'] = None
173
- error_print(f'Error capturing current path to delete temporary directory! Error: {str(e)}')
174
-
175
- finally:
176
- return result
rpa_suite/log/__init__.py DELETED
@@ -1 +0,0 @@
1
- # /__init__.py
@@ -1,172 +0,0 @@
1
- # /functions_logger_uru.py
2
-
3
- from loguru import logger
4
- from rpa_suite.log.printer import error_print, alert_print
5
- import inspect, os
6
-
7
- def log_start_run_debug(msg_start_loggin: str) -> None: # represent start application
8
-
9
- """
10
- Function responsable to generate ``start run log level debug``, in file and print on terminal the same log captured on this call.
11
- """
12
-
13
- file_h: False
14
-
15
- try:
16
-
17
- from .logger_uru import config_logger
18
- file_h = config_logger()
19
-
20
- except Exception as e:
21
-
22
- error_print(f'To use log_start_run_debug you need instance file_handler using file "logger_uru" on one file in your project! Error: {str(e)}')
23
-
24
- try:
25
- try:
26
- if file_h:
27
- with open(file_h, 'a') as f:
28
- f.write('\n')
29
-
30
- except Exception as e:
31
- alert_print(f"Don't able to break_row for initial log!")
32
-
33
- # logger.debug(f'{msg_start_loggin}')
34
- frame = inspect.currentframe().f_back
35
- full_path_filename = frame.f_code.co_filename
36
-
37
- # Obtenha o nome do arquivo e o nome da pasta
38
- filename = os.path.basename(full_path_filename)
39
- foldername = os.path.basename(os.path.dirname(full_path_filename))
40
-
41
- # Combine o nome da pasta e o nome do arquivo
42
- filename = os.path.join(foldername, filename)
43
- lineno = frame.f_lineno
44
-
45
- # Vincule o nome do arquivo e a linha à mensagem de log
46
- logger.bind(filename=filename, lineno=lineno).debug(f'{msg_start_loggin}')
47
-
48
- except Exception as e:
49
- error_print(f'Error to execute function:{log_start_run_debug.__name__}! Error: {str(e)}')
50
-
51
-
52
- def log_debug(msg) -> None:
53
-
54
- """
55
- Function responsable to generate log level ``debug``, in file and print on terminal the same log captured on this call.
56
- """
57
-
58
- try:
59
- frame = inspect.currentframe().f_back
60
- full_path_filename = frame.f_code.co_filename
61
-
62
- # Obtem o nome do arquivo e o nome da pasta
63
- filename = os.path.basename(full_path_filename)
64
- foldername = os.path.basename(os.path.dirname(full_path_filename))
65
-
66
- # Combina o nome da pasta e o nome do arquivo
67
- filename = os.path.join(foldername, filename)
68
- lineno = frame.f_lineno
69
-
70
- # Vincula o nome do arquivo e a linha à mensagem de log
71
- logger.bind(filename=filename, lineno=lineno).debug(msg)
72
-
73
- except Exception as e:
74
- error_print(f'Error to execute function:{log_debug.__name__}! Error: {str(e)}')
75
-
76
- def log_info(msg) -> None:
77
-
78
- """
79
- Function responsable to generate log level ``info``, in file and print on terminal the same log captured on this call.
80
- """
81
-
82
- try:
83
- frame = inspect.currentframe().f_back
84
- full_path_filename = frame.f_code.co_filename
85
-
86
- # Obtem o nome do arquivo e o nome da pasta
87
- filename = os.path.basename(full_path_filename)
88
- foldername = os.path.basename(os.path.dirname(full_path_filename))
89
-
90
- # Combina o nome da pasta e o nome do arquivo
91
- filename = os.path.join(foldername, filename)
92
- lineno = frame.f_lineno
93
-
94
- # Vincula o nome do arquivo e a linha à mensagem de log
95
- logger.bind(filename=filename, lineno=lineno).info(msg)
96
-
97
- except Exception as e:
98
- error_print(f'Error to execute function:{log_info.__name__}! Error: {str(e)}')
99
-
100
- def log_warning(msg) -> None:
101
-
102
- """
103
- Function responsable to generate log level ``warning``, in file and print on terminal the same log captured on this call.
104
- """
105
-
106
- try:
107
- frame = inspect.currentframe().f_back
108
- full_path_filename = frame.f_code.co_filename
109
-
110
- # Obtenha o nome do arquivo e o nome da pasta
111
- filename = os.path.basename(full_path_filename)
112
- foldername = os.path.basename(os.path.dirname(full_path_filename))
113
-
114
- # Combine o nome da pasta e o nome do arquivo
115
- filename = os.path.join(foldername, filename)
116
- lineno = frame.f_lineno
117
-
118
- # Vincule o nome do arquivo e a linha à mensagem de log
119
- logger.bind(filename=filename, lineno=lineno).warning(msg)
120
-
121
- except Exception as e:
122
- error_print(f'Error to execute function:{log_warning.__name__}! Error: {str(e)}')
123
-
124
-
125
- def log_error(msg) -> None:
126
-
127
- """
128
- Function responsable to generate log level ``error``, in file and print on terminal the same log captured on this call.
129
- """
130
-
131
- try:
132
- frame = inspect.currentframe().f_back
133
- full_path_filename = frame.f_code.co_filename
134
-
135
- # Obtenha o nome do arquivo e o nome da pasta
136
- filename = os.path.basename(full_path_filename)
137
- foldername = os.path.basename(os.path.dirname(full_path_filename))
138
-
139
- # Combine o nome da pasta e o nome do arquivo
140
- filename = os.path.join(foldername, filename)
141
- lineno = frame.f_lineno
142
-
143
- # Vincule o nome do arquivo e a linha à mensagem de log
144
- logger.bind(filename=filename, lineno=lineno).error(msg)
145
-
146
- except Exception as e:
147
- error_print(f'Error to execute function:{log_error.__name__}! Error: {str(e)}')
148
-
149
-
150
- def log_critical(msg) -> None:
151
-
152
- """
153
- Function responsable to generate log level ``critical``, in file and print on terminal the same log captured on this call.
154
- """
155
-
156
- try:
157
- frame = inspect.currentframe().f_back
158
- full_path_filename = frame.f_code.co_filename
159
-
160
- # Obtenha o nome do arquivo e o nome da pasta
161
- filename = os.path.basename(full_path_filename)
162
- foldername = os.path.basename(os.path.dirname(full_path_filename))
163
-
164
- # Combine o nome da pasta e o nome do arquivo
165
- filename = os.path.join(foldername, filename)
166
- lineno = frame.f_lineno
167
-
168
- # Vincule o nome do arquivo e a linha à mensagem de log
169
- logger.bind(filename=filename, lineno=lineno).critical(msg)
170
-
171
- except Exception as e:
172
- error_print(f'Error to execute function:{log_critical.__name__}! Error: {str(e)}')
@@ -1,37 +0,0 @@
1
- # /log_decorator.py
2
-
3
- from typing import Callable
4
- from loguru import logger
5
-
6
- def logging_decorator(
7
- fn: Callable
8
- ) -> Callable:
9
-
10
- """
11
- Function responsible for displaying log message in the console for functions that are called. \n
12
- Displays function name, and the result of the function in case of return, without return returns None.
13
-
14
- Return:
15
- ----------
16
- A ``wrapper`` function with python decoration ``@logger.catch`` that received:
17
- * ``*args and **kwargs`` in the call parameters as an argument to result in the Log.
18
-
19
- Description: pt-br
20
- ----------
21
- Função responsavel por exibir mensagem de log no console para funções que são chamadas. \n
22
- Exibe nome da função, e o resultado da função em caso de retorno, sem retorno devolve None.
23
-
24
- Retorno:
25
- ----------
26
- Uma função ``wrapper`` com decoração ``@logger.catch`` do python que recebeu:
27
- * ``*args e **kwargs`` nos parametros de chamada como argumento para resultar no Log.
28
- """
29
-
30
- @logger.catch
31
- def wrapper(*args, **kwargs):
32
- logger.info('Function Called: {}', fn.__name__)
33
- result = fn(*args, **kwargs)
34
- logger.info('Function {} returned: {}', fn.__name__, result)
35
- return result
36
-
37
- return wrapper