libretificacaotjcore 0.1.8__py3-none-any.whl → 0.1.10__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.

@@ -1,130 +1,53 @@
1
1
  import asyncio
2
+ from io import BytesIO
2
3
  import os
3
4
  import shutil
4
5
  from pathlib import Path
6
+ import zipfile
5
7
  import aiofiles
6
8
  import aiofiles.os
7
- import py7zr
8
9
 
9
10
  class FileService:
10
- # async def zip_folder(self, folder_path: str, output_path: str):
11
- # buffer = BytesIO()
11
+ async def zip_folder(self, folder_path: str, output_path: str):
12
+ buffer = BytesIO()
12
13
 
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)
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)
22
23
 
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
24
+ async with aiofiles.open(output_path, "wb") as f:
25
+ await f.write(buffer.getvalue())
80
26
 
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}")
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
+ )
100
32
 
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}")
33
+ if not await aiofiles.os.path.exists(output_path):
34
+ await aiofiles.os.makedirs(output_path, exist_ok=True)
107
35
 
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)
36
+ loop = asyncio.get_event_loop()
37
+ await loop.run_in_executor(
38
+ None, self._extrair_zip, folder_path_zip, output_path
39
+ )
117
40
 
118
41
  async def remove_file(self, file_path: str):
119
- """
120
- Remove um arquivo de forma assíncrona.
121
- """
122
42
  if await aiofiles.os.path.exists(file_path):
123
43
  await aiofiles.os.remove(file_path)
124
-
44
+
125
45
  async def remove_folder(self, folder_path: str):
126
- """
127
- Remove uma pasta inteira de forma assíncrona.
128
- """
129
46
  if await aiofiles.os.path.exists(folder_path):
130
- await asyncio.to_thread(shutil.rmtree, 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.10
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
@@ -5,10 +5,10 @@ libretificacaotjcore/database/config_db.py,sha256=ydY83Xn16DcAO-apH1nIJ1hKL_38hE
5
5
  libretificacaotjcore/dtos/solicitacao_dto.py,sha256=A0QU6MwuyK6Z2vYy4FknSAOfebpY4txB-YmgpFhAVCY,2460
6
6
  libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  libretificacaotjcore/services/crypto_pass_service.py,sha256=HdZ7IqrPOf55CpxJgn6EaZfxiOC6TycNAnBhehYn8U8,283
8
- libretificacaotjcore/services/file_service.py,sha256=SpNXC_2QF5Rlj9FVAIx_ZNnaQ6hrPBIGHazapl7qKTM,5290
8
+ libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
9
9
  libretificacaotjcore/services/rabbitmq_consumer.py,sha256=a25mRHjbkgO3lkdCJ5NpJfWAGHhVkQDCRDR2t8hMNAI,1710
10
10
  libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
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,,
11
+ libretificacaotjcore-0.1.10.dist-info/METADATA,sha256=pNtqklsOV1siH1M3jb529ce9nDaTJ1tLlXymiucOgCA,1468
12
+ libretificacaotjcore-0.1.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ libretificacaotjcore-0.1.10.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
14
+ libretificacaotjcore-0.1.10.dist-info/RECORD,,