libretificacaotjcore 0.1.8__tar.gz → 0.1.9__tar.gz

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.

Potentially problematic release.


This version of libretificacaotjcore might be problematic. Click here for more details.

Files changed (20) hide show
  1. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/PKG-INFO +1 -1
  2. libretificacaotjcore-0.1.9/libretificacaotjcore/services/file_service.py +53 -0
  3. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore.egg-info/PKG-INFO +1 -1
  4. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/pyproject.toml +1 -1
  5. libretificacaotjcore-0.1.8/libretificacaotjcore/services/file_service.py +0 -130
  6. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/README.md +0 -0
  7. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/__init__.py +0 -0
  8. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/database/__init__.py +0 -0
  9. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/database/arquivo_repository.py +0 -0
  10. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/database/config_db.py +0 -0
  11. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/dtos/solicitacao_dto.py +0 -0
  12. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/services/__init__.py +0 -0
  13. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/services/crypto_pass_service.py +0 -0
  14. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/services/rabbitmq_consumer.py +0 -0
  15. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore/services/s3_service.py +0 -0
  16. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore.egg-info/SOURCES.txt +0 -0
  17. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore.egg-info/dependency_links.txt +0 -0
  18. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore.egg-info/requires.txt +0 -0
  19. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/libretificacaotjcore.egg-info/top_level.txt +0 -0
  20. {libretificacaotjcore-0.1.8 → libretificacaotjcore-0.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libretificacaotjcore
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Biblioteca para centralizar conexao com filas no rabbit e banco de dados no mongodb para os servicos de retificacao da TJ
5
5
  Author-email: Jhonatan Azevedo <dev.azevedo@outlook.com>
6
6
  Project-URL: Homepage, https://github.com/seu-usuario/libretificacaotjcore
@@ -0,0 +1,53 @@
1
+ import asyncio
2
+ from io import BytesIO
3
+ import os
4
+ import shutil
5
+ from pathlib import Path
6
+ import zipfile
7
+ import aiofiles
8
+ import aiofiles.os
9
+
10
+ class FileService:
11
+ async def zip_folder(self, folder_path: str, output_path: str):
12
+ buffer = BytesIO()
13
+
14
+ with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
15
+ for root, _, files in os.walk(folder_path):
16
+ for file in files:
17
+ full_path = os.path.join(root, file)
18
+ arcname = os.path.relpath(full_path, folder_path)
19
+
20
+ async with aiofiles.open(full_path, "rb") as f:
21
+ content = await f.read()
22
+ zip_file.writestr(arcname, content)
23
+
24
+ async with aiofiles.open(output_path, "wb") as f:
25
+ await f.write(buffer.getvalue())
26
+
27
+ async def extract_zip(self, folder_path_zip: str, output_path: str):
28
+ if not await aiofiles.os.path.exists(folder_path_zip):
29
+ raise FileNotFoundError(
30
+ f"Arquivo ZIP não encontrado: {folder_path_zip}"
31
+ )
32
+
33
+ if not await aiofiles.os.path.exists(output_path):
34
+ await aiofiles.os.makedirs(output_path, exist_ok=True)
35
+
36
+ loop = asyncio.get_event_loop()
37
+ await loop.run_in_executor(
38
+ None, self._extrair_zip, folder_path_zip, output_path
39
+ )
40
+
41
+ async def remove_file(self, file_path: str):
42
+ if await aiofiles.os.path.exists(file_path):
43
+ await aiofiles.os.remove(file_path)
44
+
45
+ async def remove_folder(self, folder_path: str):
46
+ if await aiofiles.os.path.exists(folder_path):
47
+ loop = asyncio.get_running_loop()
48
+ await loop.run_in_executor(None, shutil.rmtree, folder_path)
49
+
50
+ def _extrair_zip(self, folder_path_zip: str, output_path: str):
51
+ with zipfile.ZipFile(folder_path_zip, "r") as zip_ref:
52
+ zip_ref.extractall(output_path)
53
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libretificacaotjcore
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Biblioteca para centralizar conexao com filas no rabbit e banco de dados no mongodb para os servicos de retificacao da TJ
5
5
  Author-email: Jhonatan Azevedo <dev.azevedo@outlook.com>
6
6
  Project-URL: Homepage, https://github.com/seu-usuario/libretificacaotjcore
@@ -11,7 +11,7 @@ keywords = ["tj", "tributo justo", "retificação", "automação", "pydantic", "
11
11
  name = "libretificacaotjcore"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.12"
14
- version = "0.1.8"
14
+ version = "0.1.9"
15
15
 
16
16
  classifiers = [
17
17
  "Development Status :: 3 - Alpha",
@@ -1,130 +0,0 @@
1
- import asyncio
2
- import os
3
- import shutil
4
- from pathlib import Path
5
- import aiofiles
6
- import aiofiles.os
7
- import py7zr
8
-
9
- class FileService:
10
- # async def zip_folder(self, folder_path: str, output_path: str):
11
- # buffer = BytesIO()
12
-
13
- # with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
14
- # for root, _, files in os.walk(folder_path):
15
- # for file in files:
16
- # full_path = os.path.join(root, file)
17
- # arcname = os.path.relpath(full_path, folder_path)
18
-
19
- # async with aiofiles.open(full_path, "rb") as f:
20
- # content = await f.read()
21
- # zip_file.writestr(arcname, content)
22
-
23
- # async with aiofiles.open(output_path, "wb") as f:
24
- # await f.write(buffer.getvalue())
25
-
26
- # async def extract_zip(self, folder_path_zip: str, output_path: str):
27
- # if not await aiofiles.os.path.exists(folder_path_zip):
28
- # raise FileNotFoundError(
29
- # f"Arquivo ZIP não encontrado: {folder_path_zip}"
30
- # )
31
-
32
- # if not await aiofiles.os.path.exists(output_path):
33
- # await aiofiles.os.makedirs(output_path, exist_ok=True)
34
-
35
- # loop = asyncio.get_event_loop()
36
- # await loop.run_in_executor(
37
- # None, self._extrair_zip, folder_path_zip, output_path
38
- # )
39
-
40
- # async def remove_file(self, file_path: str):
41
- # if await aiofiles.os.path.exists(file_path):
42
- # await aiofiles.os.remove(file_path)
43
-
44
- # async def remove_folder(self, folder_path: str):
45
- # if await aiofiles.os.path.exists(folder_path):
46
- # loop = asyncio.get_running_loop()
47
- # await loop.run_in_executor(None, shutil.rmtree, folder_path)
48
-
49
- # def _extrair_zip(self, folder_path_zip: str, output_path: str):
50
- # with zipfile.ZipFile(folder_path_zip, "r") as zip_ref:
51
- # zip_ref.extractall(output_path)
52
-
53
- ################################################################################
54
-
55
- def __init__(self, threads: int = 1):
56
- # Se não especificado, usa todos os núcleos disponíveis
57
- self.threads = threads or os.cpu_count()
58
-
59
- async def compress_folder(self, folder_path: str, output_path: str):
60
- """
61
- Compacta uma pasta inteira para .7z de forma mais robusta.
62
- """
63
- if not await aiofiles.os.path.exists(folder_path):
64
- raise FileNotFoundError(f"Pasta não encontrada: {folder_path}")
65
-
66
- os.makedirs(os.path.dirname(output_path), exist_ok=True)
67
-
68
- await asyncio.to_thread(
69
- self._compress_folder_sync, folder_path, output_path
70
- )
71
-
72
- def _compress_folder_sync(self, folder_path: str, output_path: str):
73
- # Tentar diferentes configurações em ordem de preferência
74
- configurations = [
75
- # Configuração 1: LZMA2 com preset
76
- {"filters": [{"id": py7zr.FILTER_LZMA2, "preset": py7zr.PRESET_DEFAULT}]},
77
-
78
- # Configuração 2: LZMA2 com parâmetros manuais válidos
79
- {"filters": [{"id": py7zr.FILTER_LZMA2, "dict_size": 16777216}]}, # 16MB
80
-
81
- # Configuração 3: Padrão sem filtros customizados
82
- {}
83
- ]
84
-
85
- last_error = None
86
- for i, config in enumerate(configurations):
87
- try:
88
- print(f"Tentando configuração {i + 1}...")
89
- with py7zr.SevenZipFile(output_path, mode="w", **config) as archive:
90
- archive.writeall(folder_path, arcname="")
91
- print(f"Sucesso com configuração {i + 1}!")
92
- return
93
- except Exception as e:
94
- print(f"Configuração {i + 1} falhou: {e}")
95
- last_error = e
96
- continue
97
-
98
- # Se todas as configurações falharam
99
- raise Exception(f"Todas as configurações falharam. Último erro: {last_error}")
100
-
101
- async def extract_file(self, file_path_7z: str, output_path: str):
102
- """
103
- Extrai um arquivo .7z de forma assíncrona.
104
- """
105
- if not await aiofiles.os.path.exists(file_path_7z):
106
- raise FileNotFoundError(f"Arquivo 7z não encontrado: {file_path_7z}")
107
-
108
- os.makedirs(output_path, exist_ok=True)
109
-
110
- await asyncio.to_thread(
111
- self._extract_7z_sync, file_path_7z, output_path
112
- )
113
-
114
- def _extract_7z_sync(self, file_path_7z: str, output_path: str):
115
- with py7zr.SevenZipFile(file_path_7z, mode="r") as archive:
116
- archive.extractall(path=output_path)
117
-
118
- async def remove_file(self, file_path: str):
119
- """
120
- Remove um arquivo de forma assíncrona.
121
- """
122
- if await aiofiles.os.path.exists(file_path):
123
- await aiofiles.os.remove(file_path)
124
-
125
- async def remove_folder(self, folder_path: str):
126
- """
127
- Remove uma pasta inteira de forma assíncrona.
128
- """
129
- if await aiofiles.os.path.exists(folder_path):
130
- await asyncio.to_thread(shutil.rmtree, folder_path)