saviialib 0.9.0__py3-none-any.whl → 0.9.1__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.

@@ -36,28 +36,32 @@ class UploadBackupToSharepointUsecase:
36
36
  self.sharepoint_config = input.sharepoint_config
37
37
  self.local_backup_source_path = input.local_backup_source_path
38
38
  self.destination_folders = input.destination_folders
39
- self.grouped_files_by_folder = self._extract_filesnames_by_folder()
40
39
  self.files_client = self._initialize_files_client()
41
- self.total_files = sum(
42
- len(files) for files in self.grouped_files_by_folder.values()
43
- )
44
40
  self.log_history = []
41
+ self.grouped_files_by_folder = None
42
+ self.total_files = None
45
43
 
46
44
  def _initialize_files_client(self):
47
45
  return FilesClient(FilesClientInitArgs(client_name="aiofiles_client"))
48
46
 
49
- def _extract_filesnames_by_folder(self) -> dict[str, list[str]]:
47
+ async def _extract_filesnames_by_folder(self) -> dict[str, list[str]]:
50
48
  """Groups files by their parent folder."""
51
- if not os.path.exists(self.local_backup_source_path):
49
+ backup_folder_exists = await asyncio.to_thread(
50
+ os.path.exists, self.local_backup_source_path
51
+ )
52
+ if not backup_folder_exists:
52
53
  return {}
54
+ folder_names = await asyncio.to_thread(
55
+ os.listdir, self.local_backup_source_path
56
+ )
53
57
  return {
54
58
  folder_name: [
55
59
  file_name
56
- for file_name in os.listdir(
57
- os.path.join(self.local_backup_source_path, folder_name)
60
+ for file_name in await asyncio.to_thread(
61
+ os.listdir, os.path.join(self.local_backup_source_path, folder_name)
58
62
  )
59
63
  ]
60
- for folder_name in os.listdir(self.local_backup_source_path)
64
+ for folder_name in folder_names
61
65
  }
62
66
 
63
67
  def _save_log_history(self) -> None:
@@ -84,7 +88,9 @@ class UploadBackupToSharepointUsecase:
84
88
 
85
89
  async with sharepoint_client:
86
90
  try:
87
- destination_folder = self.destination_folders.get(folder_name, folder_name)
91
+ destination_folder = self.destination_folders.get(
92
+ folder_name, folder_name
93
+ )
88
94
  folder_url = f"{c.SHAREPOINT_BASE_URL}/{destination_folder}"
89
95
  args = SpUploadFileArgs(
90
96
  folder_relative_url=folder_url,
@@ -150,20 +156,33 @@ class UploadBackupToSharepointUsecase:
150
156
 
151
157
  async def execute(self):
152
158
  """Exports all files from the local backup folder to SharePoint cloud."""
159
+ self.grouped_files_by_folder = await self._extract_filesnames_by_folder()
160
+ self.total_files = sum(
161
+ len(files) for files in self.grouped_files_by_folder.values()
162
+ )
153
163
  tasks = []
154
164
  start_time = time()
155
-
165
+
156
166
  # Check if the local path exists in the main directory
157
- if not directory_exists(self.local_backup_source_path):
167
+ if not await directory_exists(self.local_backup_source_path):
158
168
  raise BackupSourcePathError(
159
169
  reason=f"'{self.local_backup_source_path}' doesn't exist."
160
170
  )
161
171
 
162
172
  # Check if the current folder only have files.
163
- for item in os.listdir(self.local_backup_source_path):
173
+ items = [
174
+ item
175
+ for item in await asyncio.to_thread(
176
+ os.listdir, self.local_backup_source_path
177
+ )
178
+ ]
179
+ for item in items:
164
180
  folder_included = item in self.destination_folders.keys()
165
- is_file = not os.path.isdir(os.path.join(self.local_backup_source_path, item))
166
- if not folder_included and not is_file:
181
+ is_file = not await asyncio.to_thread(
182
+ os.path.isdir, os.path.join(self.local_backup_source_path, item)
183
+ )
184
+
185
+ if not folder_included and not is_file:
167
186
  raise BackupSourcePathError(
168
187
  reason=(
169
188
  f"'{item}' must be included in the destination folders dictionary",
@@ -171,12 +190,8 @@ class UploadBackupToSharepointUsecase:
171
190
  )
172
191
  elif folder_included and is_file:
173
192
  print(folder_included, is_file)
174
- raise BackupSourcePathError(
175
- reason=(
176
- f"'{item}' must be a directory.",
177
- )
178
- )
179
-
193
+ raise BackupSourcePathError(reason=(f"'{item}' must be a directory.",))
194
+
180
195
  if self.total_files == 0:
181
196
  no_files_message = (
182
197
  f"[BACKUP] {self.local_backup_source_path} has no files ⚠️"
@@ -187,7 +202,9 @@ class UploadBackupToSharepointUsecase:
187
202
  # Create task for each file stored in the the local backup folder.
188
203
  for folder_name in self.grouped_files_by_folder:
189
204
  if (
190
- count_files_in_directory(self.local_backup_source_path, folder_name)
205
+ await count_files_in_directory(
206
+ self.local_backup_source_path, folder_name
207
+ )
191
208
  == 0
192
209
  ):
193
210
  empty_folder_message = f"[BACKUP] The folder '{folder_name}' is empty ⚠️"
@@ -1,5 +1,6 @@
1
1
  import re
2
2
  from typing import List, Dict, Optional
3
+ import asyncio
3
4
  import os
4
5
  from saviialib.general_types.error_types.api.epii_api_error_types import (
5
6
  BackupSourcePathError,
@@ -93,9 +94,9 @@ def calculate_percentage_uploaded(results: List[Dict], total_files: int) -> floa
93
94
  return (uploaded_count / total_files) * 100 if total_files > 0 else 0
94
95
 
95
96
 
96
- def directory_exists(path: str) -> bool:
97
- return os.path.exists(path)
97
+ async def directory_exists(path: str) -> bool:
98
+ return await asyncio.to_thread(os.path.exists, path)
98
99
 
99
100
 
100
- def count_files_in_directory(path: str, folder_name: str) -> int:
101
- return len(os.listdir(os.path.join(path, folder_name)))
101
+ async def count_files_in_directory(path: str, folder_name: str) -> int:
102
+ return len(await asyncio.to_thread(os.listdir, os.path.join(path, folder_name)))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: saviialib
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: A client library for IoT projects in the RCER initiative
5
5
  License: MIT
6
6
  Author: pedropablozavalat
@@ -39,11 +39,11 @@ saviialib/services/epii/use_cases/types/__init__.py,sha256=u6fyodOEJE2j6FMqJux40
39
39
  saviialib/services/epii/use_cases/types/update_thies_data_types.py,sha256=BoT6N9YoVw3f8Cyb88T7fJTCCnkVybOh1K1u2fJ3X7k,419
40
40
  saviialib/services/epii/use_cases/types/upload_backup_to_sharepoint_types.py,sha256=rvuhJnjsCQpuNz5UO_0lGMR_KJRybNdq_11Be9ZaY1U,267
41
41
  saviialib/services/epii/use_cases/update_thies_data.py,sha256=WLBpdAUkxAL_XdDnc49scmst1xMjrdScjr6Cmgg3UEE,6494
42
- saviialib/services/epii/use_cases/upload_backup_to_sharepoint.py,sha256=3XrkE2LNw3DRP3FA0SVpdD4AnCIL6uBSA-9sctjfKyw,9144
42
+ saviialib/services/epii/use_cases/upload_backup_to_sharepoint.py,sha256=rurCi-01Rm1SKa6o_SPcbsnOBfHlUD1ZMmIn6k7JbCQ,9608
43
43
  saviialib/services/epii/utils/__init__.py,sha256=cYt2tvq65_OMjFaqb8-CCC7IGCQgFd4ziEUWJV7s1iY,98
44
44
  saviialib/services/epii/utils/update_thies_data_utils.py,sha256=EpjYWXqyHxJ-dO3MHhdXp-rGV7WyUckeFko-nnfnNac,555
45
- saviialib/services/epii/utils/upload_backup_to_sharepoint_utils.py,sha256=4psc4EHpgnuiOVc0Tn_PR2mDsDh774ERbhIewSwYSZg,3422
46
- saviialib-0.9.0.dist-info/LICENSE,sha256=NWpf6b38xgBWPBo5HZsCbdfp9hZSliEbRqWQgm0fkOo,1076
47
- saviialib-0.9.0.dist-info/METADATA,sha256=WnSLd2VoJRXqhypq0NXow8eqQ8Pu9swBbSn9oX5BPhc,4082
48
- saviialib-0.9.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
49
- saviialib-0.9.0.dist-info/RECORD,,
45
+ saviialib/services/epii/utils/upload_backup_to_sharepoint_utils.py,sha256=DnV4ddqZ0eeD50Wh66J9__m3Sqk5-1p_93e9YuQitpA,3499
46
+ saviialib-0.9.1.dist-info/LICENSE,sha256=NWpf6b38xgBWPBo5HZsCbdfp9hZSliEbRqWQgm0fkOo,1076
47
+ saviialib-0.9.1.dist-info/METADATA,sha256=8xbbpq_CG90pYR9SaNjkuVcGPM2vZ0-9qPrjd8aHazo,4082
48
+ saviialib-0.9.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
49
+ saviialib-0.9.1.dist-info/RECORD,,