libretificacaotjcore 0.1.7__py3-none-any.whl → 0.1.8__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.
Potentially problematic release.
This version of libretificacaotjcore might be problematic. Click here for more details.
- libretificacaotjcore/services/crypto_pass_service.py +11 -0
- libretificacaotjcore/services/file_service.py +110 -33
- {libretificacaotjcore-0.1.7.dist-info → libretificacaotjcore-0.1.8.dist-info}/METADATA +3 -1
- {libretificacaotjcore-0.1.7.dist-info → libretificacaotjcore-0.1.8.dist-info}/RECORD +6 -5
- {libretificacaotjcore-0.1.7.dist-info → libretificacaotjcore-0.1.8.dist-info}/WHEEL +0 -0
- {libretificacaotjcore-0.1.7.dist-info → libretificacaotjcore-0.1.8.dist-info}/top_level.txt +0 -0
|
@@ -1,53 +1,130 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
from io import BytesIO
|
|
3
2
|
import os
|
|
4
3
|
import shutil
|
|
5
|
-
import zipfile
|
|
6
4
|
from pathlib import Path
|
|
7
5
|
import aiofiles
|
|
8
6
|
import aiofiles.os
|
|
7
|
+
import py7zr
|
|
9
8
|
|
|
10
9
|
class FileService:
|
|
11
|
-
async def zip_folder(self, folder_path: str, output_path: str):
|
|
12
|
-
|
|
10
|
+
# async def zip_folder(self, folder_path: str, output_path: str):
|
|
11
|
+
# buffer = BytesIO()
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
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)
|
|
26
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)
|
|
27
48
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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)
|
|
33
67
|
|
|
34
|
-
|
|
35
|
-
|
|
68
|
+
await asyncio.to_thread(
|
|
69
|
+
self._compress_folder_sync, folder_path, output_path
|
|
70
|
+
)
|
|
36
71
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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)
|
|
41
117
|
|
|
42
118
|
async def remove_file(self, file_path: str):
|
|
119
|
+
"""
|
|
120
|
+
Remove um arquivo de forma assíncrona.
|
|
121
|
+
"""
|
|
43
122
|
if await aiofiles.os.path.exists(file_path):
|
|
44
123
|
await aiofiles.os.remove(file_path)
|
|
45
|
-
|
|
124
|
+
|
|
46
125
|
async def remove_folder(self, folder_path: str):
|
|
126
|
+
"""
|
|
127
|
+
Remove uma pasta inteira de forma assíncrona.
|
|
128
|
+
"""
|
|
47
129
|
if await aiofiles.os.path.exists(folder_path):
|
|
48
|
-
|
|
49
|
-
await loop.run_in_executor(None, shutil.rmtree, folder_path)
|
|
50
|
-
|
|
51
|
-
def _extrair_zip(self, folder_path_zip: str, output_path: str):
|
|
52
|
-
with zipfile.ZipFile(folder_path_zip, "r") as zip_ref:
|
|
53
|
-
zip_ref.extractall(output_path)
|
|
130
|
+
await asyncio.to_thread(shutil.rmtree, folder_path)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libretificacaotjcore
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.8
|
|
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
|
|
@@ -23,6 +23,8 @@ Requires-Python: >=3.12
|
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
24
|
Requires-Dist: aiofiles>=24.1.0
|
|
25
25
|
Requires-Dist: boto3>=1.39.16
|
|
26
|
+
Requires-Dist: cryptography>=45.0.6
|
|
26
27
|
Requires-Dist: motor>=3.7.1
|
|
27
28
|
Requires-Dist: pika>=1.3.2
|
|
29
|
+
Requires-Dist: py7zr>=1.0.0
|
|
28
30
|
Requires-Dist: pydantic>=2.11.7
|
|
@@ -4,10 +4,11 @@ libretificacaotjcore/database/arquivo_repository.py,sha256=yKyYXzTyp1xiQsI1Cjh9w
|
|
|
4
4
|
libretificacaotjcore/database/config_db.py,sha256=ydY83Xn16DcAO-apH1nIJ1hKL_38hEHeUKg5R8v8ZJI,1292
|
|
5
5
|
libretificacaotjcore/dtos/solicitacao_dto.py,sha256=A0QU6MwuyK6Z2vYy4FknSAOfebpY4txB-YmgpFhAVCY,2460
|
|
6
6
|
libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
libretificacaotjcore/services/
|
|
7
|
+
libretificacaotjcore/services/crypto_pass_service.py,sha256=HdZ7IqrPOf55CpxJgn6EaZfxiOC6TycNAnBhehYn8U8,283
|
|
8
|
+
libretificacaotjcore/services/file_service.py,sha256=SpNXC_2QF5Rlj9FVAIx_ZNnaQ6hrPBIGHazapl7qKTM,5290
|
|
8
9
|
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=a25mRHjbkgO3lkdCJ5NpJfWAGHhVkQDCRDR2t8hMNAI,1710
|
|
9
10
|
libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
|
|
10
|
-
libretificacaotjcore-0.1.
|
|
11
|
-
libretificacaotjcore-0.1.
|
|
12
|
-
libretificacaotjcore-0.1.
|
|
13
|
-
libretificacaotjcore-0.1.
|
|
11
|
+
libretificacaotjcore-0.1.8.dist-info/METADATA,sha256=UKGi6EoT_gLuCJhOiFfjMYvWRTNDf0Dw9M2ahrE5dKI,1467
|
|
12
|
+
libretificacaotjcore-0.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
libretificacaotjcore-0.1.8.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
|
|
14
|
+
libretificacaotjcore-0.1.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|