saviialib 0.11.0__py3-none-any.whl → 0.11.2__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 saviialib might be problematic. Click here for more details.
- saviialib/general_types/api/epii_api_types.py +1 -0
- saviialib/libs/ftp_client/clients/aioftp_client.py +5 -2
- saviialib/services/epii/api.py +3 -1
- saviialib/services/epii/controllers/update_thies_data.py +1 -0
- saviialib/services/epii/use_cases/types/update_thies_data_types.py +2 -0
- saviialib/services/epii/use_cases/update_thies_data.py +47 -14
- {saviialib-0.11.0.dist-info → saviialib-0.11.2.dist-info}/METADATA +1 -1
- {saviialib-0.11.0.dist-info → saviialib-0.11.2.dist-info}/RECORD +10 -10
- {saviialib-0.11.0.dist-info → saviialib-0.11.2.dist-info}/LICENSE +0 -0
- {saviialib-0.11.0.dist-info → saviialib-0.11.2.dist-info}/WHEEL +0 -0
|
@@ -45,5 +45,8 @@ class AioFTPClient(FTPClientContract):
|
|
|
45
45
|
|
|
46
46
|
async def read_file(self, args: FtpReadFileArgs) -> bytes:
|
|
47
47
|
await self._async_start()
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
try:
|
|
49
|
+
async with self.client.download_stream(args.file_path) as stream: # type: ignore
|
|
50
|
+
return await stream.read()
|
|
51
|
+
except StatusCodeError as error:
|
|
52
|
+
raise FileNotFoundError(f"File not found: {args.file_path}") from error
|
saviialib/services/epii/api.py
CHANGED
|
@@ -28,7 +28,6 @@ class EpiiAPI:
|
|
|
28
28
|
self.sharepoint_tenant_id = config.sharepoint_tenant_id
|
|
29
29
|
self.sharepoint_tenant_name = config.sharepoint_tenant_name
|
|
30
30
|
self.sharepoint_site_name = config.sharepoint_site_name
|
|
31
|
-
|
|
32
31
|
self.logger = config.logger
|
|
33
32
|
|
|
34
33
|
async def update_thies_data(
|
|
@@ -39,7 +38,9 @@ class EpiiAPI:
|
|
|
39
38
|
|
|
40
39
|
Args:
|
|
41
40
|
sharepoint_folders_path (list): List of Sharepoint folder paths for AVG and EXT data.
|
|
41
|
+
The AVG path must be the first element.
|
|
42
42
|
ftp_server_folders_path (list): List of FTP server folder paths for AVG and EXT data.
|
|
43
|
+
The AVG path must be the first element.
|
|
43
44
|
|
|
44
45
|
Returns:
|
|
45
46
|
dict: A dictionary representation of the API response.
|
|
@@ -54,6 +55,7 @@ class EpiiAPI:
|
|
|
54
55
|
sharepoint_site_name=self.sharepoint_site_name,
|
|
55
56
|
sharepoint_tenant_id=self.sharepoint_tenant_id,
|
|
56
57
|
sharepoint_tenant_name=self.sharepoint_tenant_name,
|
|
58
|
+
logger=self.logger,
|
|
57
59
|
)
|
|
58
60
|
controller = UpdateThiesDataController(
|
|
59
61
|
UpdateThiesDataControllerInput(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
2
|
from typing import Dict, List
|
|
3
3
|
from saviialib.general_types.api.epii_api_types import FtpClientConfig, SharepointConfig
|
|
4
|
+
from logging import Logger
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
@dataclass
|
|
@@ -9,6 +10,7 @@ class UpdateThiesDataUseCaseInput:
|
|
|
9
10
|
sharepoint_config: SharepointConfig
|
|
10
11
|
sharepoint_folders_path: List
|
|
11
12
|
ftp_server_folders_path: List
|
|
13
|
+
logger: Logger
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
@dataclass
|
|
@@ -38,6 +38,7 @@ class UpdateThiesDataUseCase:
|
|
|
38
38
|
self.sharepoint_client = self._initialize_sharepoint_client(
|
|
39
39
|
input.sharepoint_config
|
|
40
40
|
)
|
|
41
|
+
self.logger = input.logger
|
|
41
42
|
self.thies_ftp_client = self._initialize_thies_ftp_client(input.ftp_config)
|
|
42
43
|
self.sharepoint_folders_path = input.sharepoint_folders_path
|
|
43
44
|
self.ftp_server_folders_path = input.ftp_server_folders_path
|
|
@@ -122,16 +123,25 @@ class UpdateThiesDataUseCase:
|
|
|
122
123
|
try:
|
|
123
124
|
content_files = {}
|
|
124
125
|
for file in self.uploading:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
prefix, filename = file.split("_", 1)
|
|
127
|
+
# The first path is for AVG files. The second file is for EXT files
|
|
128
|
+
folder_path = next(
|
|
129
|
+
(
|
|
130
|
+
path
|
|
131
|
+
for path in self.ftp_server_folders_path
|
|
132
|
+
if prefix == ("AVG" if "AV" in path else "EXT")
|
|
133
|
+
),
|
|
134
|
+
self.ftp_server_folders_path[0], # Default to the first path
|
|
130
135
|
)
|
|
131
136
|
file_path = f"{folder_path}/{filename}"
|
|
132
137
|
content = await self.thies_ftp_client.read_file(
|
|
133
138
|
FtpReadFileArgs(file_path)
|
|
134
139
|
)
|
|
140
|
+
self.logger.debug(
|
|
141
|
+
"[thies_synchronization_lib] Fetching file '%s' from '%s'.",
|
|
142
|
+
file,
|
|
143
|
+
folder_path,
|
|
144
|
+
)
|
|
135
145
|
content_files[file] = (
|
|
136
146
|
content # Save file content with its original name.
|
|
137
147
|
)
|
|
@@ -150,12 +160,17 @@ class UpdateThiesDataUseCase:
|
|
|
150
160
|
async with self.sharepoint_client:
|
|
151
161
|
for file, file_content in files.items():
|
|
152
162
|
try:
|
|
153
|
-
|
|
154
|
-
#
|
|
155
|
-
if
|
|
156
|
-
|
|
163
|
+
origin, file_name = file.split("_", 1)
|
|
164
|
+
# Check if the first folder is for AVG, otherwise assume it's for EXT
|
|
165
|
+
if "AVG" in self.sharepoint_folders_path[0]:
|
|
166
|
+
avg_folder = self.sharepoint_folders_path[0]
|
|
167
|
+
ext_folder = self.sharepoint_folders_path[1]
|
|
157
168
|
else:
|
|
158
|
-
|
|
169
|
+
avg_folder = self.sharepoint_folders_path[1]
|
|
170
|
+
ext_folder = self.sharepoint_folders_path[0]
|
|
171
|
+
|
|
172
|
+
folder_path = avg_folder if origin == "AVG" else ext_folder
|
|
173
|
+
|
|
159
174
|
relative_url = f"{self.sharepoint_base_url}/{folder_path}"
|
|
160
175
|
|
|
161
176
|
args = SpUploadFileArgs(
|
|
@@ -165,8 +180,18 @@ class UpdateThiesDataUseCase:
|
|
|
165
180
|
)
|
|
166
181
|
await self.sharepoint_client.upload_file(args)
|
|
167
182
|
upload_results["new_files"].append(file)
|
|
183
|
+
self.logger.debug(
|
|
184
|
+
"[thies_synchronization_lib] File '%s' from '%s' uploaded successfully to '%s' ✅",
|
|
185
|
+
file_name,
|
|
186
|
+
folder_path,
|
|
187
|
+
relative_url,
|
|
188
|
+
)
|
|
168
189
|
|
|
169
190
|
except ConnectionError as error:
|
|
191
|
+
self.logger.error(
|
|
192
|
+
"[thies_synchronization_lib] Unexpected error from with file '%s'",
|
|
193
|
+
file_name,
|
|
194
|
+
)
|
|
170
195
|
upload_results["failed_files"].append(
|
|
171
196
|
f"{file} (Error: {str(error)})"
|
|
172
197
|
)
|
|
@@ -181,20 +206,26 @@ class UpdateThiesDataUseCase:
|
|
|
181
206
|
|
|
182
207
|
async def execute(self):
|
|
183
208
|
"""Synchronize data from the THIES Center to the cloud."""
|
|
209
|
+
self.logger.debug("[thies_synchronization_lib] Starting ...")
|
|
184
210
|
try:
|
|
185
211
|
thies_files = await self.fetch_thies_file_names()
|
|
186
212
|
except RuntimeError as error:
|
|
187
213
|
raise FtpClientError(error)
|
|
188
|
-
|
|
214
|
+
self.logger.debug(
|
|
215
|
+
"[thies_synchronization_lib] Total files fetched from THIES: %s",
|
|
216
|
+
str(len(thies_files)),
|
|
217
|
+
)
|
|
189
218
|
try:
|
|
190
219
|
cloud_files = await self.fetch_cloud_file_names()
|
|
191
220
|
except RuntimeError as error:
|
|
192
221
|
raise SharepointClient(error) # type: ignore
|
|
193
|
-
|
|
222
|
+
self.logger.debug(
|
|
223
|
+
"[thies_synchronization_lib] Total files fetched from Sharepoint: %s",
|
|
224
|
+
str(len(cloud_files)),
|
|
225
|
+
)
|
|
194
226
|
self.uploading = thies_files - cloud_files
|
|
195
227
|
if not self.uploading:
|
|
196
228
|
raise EmptyDataError(reason="No files to upload.")
|
|
197
|
-
|
|
198
229
|
# Fetch the content of the files to be uploaded from THIES FTP Server
|
|
199
230
|
thies_fetched_files = await self.fetch_thies_file_content()
|
|
200
231
|
|
|
@@ -202,5 +233,7 @@ class UpdateThiesDataUseCase:
|
|
|
202
233
|
upload_statistics = await self.upload_thies_files_to_sharepoint(
|
|
203
234
|
thies_fetched_files
|
|
204
235
|
)
|
|
205
|
-
|
|
236
|
+
self.logger.debug(
|
|
237
|
+
"[thies_synchronization_lib] All the files were uploaded successfully 🎉"
|
|
238
|
+
)
|
|
206
239
|
return parse_execute_response(thies_fetched_files, upload_statistics) # type: ignore
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
saviialib/__init__.py,sha256=TMsEY8OOjo9KOz-0jf3QBh6WFOhCY07Rd7W2PK7C-1A,253
|
|
2
2
|
saviialib/general_types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
saviialib/general_types/api/__init__.py,sha256=jXhoMlbSv7UCizW_Fm2mqR_3n99qkocVwg6CF7s3w7w,145
|
|
4
|
-
saviialib/general_types/api/epii_api_types.py,sha256=
|
|
4
|
+
saviialib/general_types/api/epii_api_types.py,sha256=jspp5tDN06qx27O3ubRyPfZ3i9ybvn2HLxjh3UTFNcY,2345
|
|
5
5
|
saviialib/general_types/error_types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
saviialib/general_types/error_types/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
saviialib/general_types/error_types/api/epii_api_error_types.py,sha256=iprpNvVoNA3vakMm7-dQdjCv7ZrRs6tRiXK1uaV3DNU,3049
|
|
@@ -19,7 +19,7 @@ saviialib/libs/files_client/files_client_contract.py,sha256=fYvd68IMpc1OFkxbzNSm
|
|
|
19
19
|
saviialib/libs/files_client/types/files_client_types.py,sha256=8OHm4nvZTW9K3ryeIUvthE_Cj7wF4zVcqG0KCi_vQIU,718
|
|
20
20
|
saviialib/libs/ftp_client/__init__.py,sha256=dW2Yutgc7mJJJzgKLhWKXMgQ6KIWJYfFa1sGpjHH5xU,191
|
|
21
21
|
saviialib/libs/ftp_client/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
-
saviialib/libs/ftp_client/clients/aioftp_client.py,sha256=
|
|
22
|
+
saviialib/libs/ftp_client/clients/aioftp_client.py,sha256=5sgr3PMETgaBRlKeu_avxHIh6tr1gb7t2mkxmpRas_k,1925
|
|
23
23
|
saviialib/libs/ftp_client/ftp_client.py,sha256=UWpuIrfO27A1M40YaBvAUdkdwPYJ4Ty4q55x7H4y1F8,844
|
|
24
24
|
saviialib/libs/ftp_client/ftp_client_contract.py,sha256=tymkugDzsJ5PzUXIaSkwX1h7T0naR15qAkjrqswqDyM,338
|
|
25
25
|
saviialib/libs/ftp_client/types/__init__.py,sha256=syfwf9feP4QK7fkCTfl4j8l11ic-jHtfi1DE2chaWbs,155
|
|
@@ -31,23 +31,23 @@ saviialib/libs/sharepoint_client/sharepoint_client_contract.py,sha256=xqNHzCjp7G
|
|
|
31
31
|
saviialib/libs/sharepoint_client/types/sharepoint_client_types.py,sha256=OmPlCJ9rLrAFBeG6aDp5cxMiQ5BZlDyGVx5S4GN4aqg,414
|
|
32
32
|
saviialib/libs/zero_dependency/utils/datetime_utils.py,sha256=NFPHxOTuCtfkYjUnsbRqw9ZK87UGAK-Eira2CwG8rJ8,754
|
|
33
33
|
saviialib/services/epii/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
saviialib/services/epii/api.py,sha256=
|
|
34
|
+
saviialib/services/epii/api.py,sha256=99G-iC8Nz8vv9TuNPpdFsHxDAH8DXVCHnUQzwAUO9Ao,4036
|
|
35
35
|
saviialib/services/epii/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
36
|
saviialib/services/epii/controllers/types/__init__.py,sha256=xzky-oTSojLNkWETp_k8a4dcXYvYSQY0VhWo23Yhb8U,195
|
|
37
37
|
saviialib/services/epii/controllers/types/update_thies_data_types.py,sha256=kmt18vq7RLEAfIJj9MYz62fJH9etuU1WqZJ5MYmjiIg,448
|
|
38
38
|
saviialib/services/epii/controllers/types/upload_backup_to_sharepoint_types.py,sha256=5mDMLy3J5grACl1ezBGYZPOyhIkWYeIWWBOklaP2IlQ,471
|
|
39
|
-
saviialib/services/epii/controllers/update_thies_data.py,sha256=
|
|
39
|
+
saviialib/services/epii/controllers/update_thies_data.py,sha256=8TV420d4VWTvCW18M6sAguHZrX5VODXscgrUfhwO1fs,4884
|
|
40
40
|
saviialib/services/epii/controllers/upload_backup_to_sharepoint.py,sha256=7-ABo89yXhrWv-iOFjCkBGX-y_I62eFaOi1LtO5Gb4k,3817
|
|
41
41
|
saviialib/services/epii/use_cases/constants/upload_backup_to_sharepoint_constants.py,sha256=erkn-3E8YwBMFs25o7exXoK7s73NdgP9IYDXeWzALcI,98
|
|
42
42
|
saviialib/services/epii/use_cases/types/__init__.py,sha256=u6fyodOEJE2j6FMqJux40Xf9ccYAi-UUYxqT-Kzc0kE,199
|
|
43
|
-
saviialib/services/epii/use_cases/types/update_thies_data_types.py,sha256=
|
|
43
|
+
saviialib/services/epii/use_cases/types/update_thies_data_types.py,sha256=3lJzG1nuZoP1mqFlvQ0-aFJp80SECaeiROlvucVhaSY,539
|
|
44
44
|
saviialib/services/epii/use_cases/types/upload_backup_to_sharepoint_types.py,sha256=J_sGhqSaPoMZA0GIrzCx6pmgSKgIkGi0uyrsltU_H8w,320
|
|
45
|
-
saviialib/services/epii/use_cases/update_thies_data.py,sha256=
|
|
45
|
+
saviialib/services/epii/use_cases/update_thies_data.py,sha256=SKW9_Z2pbvE0rgyFHmpBynGVqfQ30OMqK3zofW_tY8Y,9866
|
|
46
46
|
saviialib/services/epii/use_cases/upload_backup_to_sharepoint.py,sha256=UZ2Pe_mavdquYG00_GYtANY4nn0wHjT_Z0HLUvtfW2c,11143
|
|
47
47
|
saviialib/services/epii/utils/__init__.py,sha256=cYt2tvq65_OMjFaqb8-CCC7IGCQgFd4ziEUWJV7s1iY,98
|
|
48
48
|
saviialib/services/epii/utils/update_thies_data_utils.py,sha256=EpjYWXqyHxJ-dO3MHhdXp-rGV7WyUckeFko-nnfnNac,555
|
|
49
49
|
saviialib/services/epii/utils/upload_backup_to_sharepoint_utils.py,sha256=hEeV4_kcG8YL6t_3V8AlhgDHtHiUNsdYpilfgTLaQMc,3528
|
|
50
|
-
saviialib-0.11.
|
|
51
|
-
saviialib-0.11.
|
|
52
|
-
saviialib-0.11.
|
|
53
|
-
saviialib-0.11.
|
|
50
|
+
saviialib-0.11.2.dist-info/LICENSE,sha256=NWpf6b38xgBWPBo5HZsCbdfp9hZSliEbRqWQgm0fkOo,1076
|
|
51
|
+
saviialib-0.11.2.dist-info/METADATA,sha256=Af3aG28BKcG0Fsfds49sWCWJTBuWs4xo--RhfBsAjSE,4083
|
|
52
|
+
saviialib-0.11.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
53
|
+
saviialib-0.11.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|