saviialib 0.9.1__py3-none-any.whl → 1.6.0__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/__init__.py +73 -3
- saviialib/general_types/api/__init__.py +0 -3
- saviialib/general_types/api/{epii_api_types.py → saviia_api_types.py} +4 -38
- saviialib/general_types/api/saviia_backup_api_types.py +24 -0
- saviialib/general_types/api/saviia_netcamera_api_types.py +11 -0
- saviialib/general_types/api/saviia_shakes_api_types.py +21 -0
- saviialib/general_types/api/saviia_thies_api_types.py +31 -0
- saviialib/general_types/error_types/api/{epii_api_error_types.py → saviia_api_error_types.py} +20 -0
- saviialib/general_types/error_types/api/saviia_netcamera_error_types.py +7 -0
- saviialib/general_types/error_types/common/common_types.py +9 -0
- saviialib/libs/directory_client/__init__.py +4 -0
- saviialib/libs/directory_client/client/os_client.py +55 -0
- saviialib/libs/directory_client/directory_client.py +44 -0
- saviialib/libs/directory_client/directory_client_contract.py +40 -0
- saviialib/libs/directory_client/types/directory_client_types.py +6 -0
- saviialib/libs/ffmpeg_client/__init__.py +8 -0
- saviialib/libs/ffmpeg_client/clients/ffmpeg_asyncio_client.py +101 -0
- saviialib/libs/ffmpeg_client/ffmpeg_client.py +25 -0
- saviialib/libs/ffmpeg_client/ffmpeg_client_contract.py +12 -0
- saviialib/libs/ffmpeg_client/types/ffmpeg_client_types.py +28 -0
- saviialib/libs/files_client/__init__.py +2 -2
- saviialib/libs/files_client/clients/aiofiles_client.py +26 -3
- saviialib/libs/files_client/clients/csv_client.py +42 -0
- saviialib/libs/files_client/files_client.py +5 -7
- saviialib/libs/files_client/types/files_client_types.py +5 -4
- saviialib/libs/ftp_client/clients/aioftp_client.py +13 -6
- saviialib/libs/ftp_client/clients/ftplib_client.py +58 -0
- saviialib/libs/ftp_client/ftp_client.py +8 -5
- saviialib/libs/ftp_client/ftp_client_contract.py +2 -2
- saviialib/libs/log_client/__init__.py +19 -0
- saviialib/libs/log_client/log_client.py +46 -0
- saviialib/libs/log_client/log_client_contract.py +28 -0
- saviialib/libs/log_client/logging_client/logging_client.py +58 -0
- saviialib/libs/log_client/types/log_client_types.py +47 -0
- saviialib/libs/log_client/utils/log_client_utils.py +6 -0
- saviialib/libs/sftp_client/__init__.py +8 -0
- saviialib/libs/sftp_client/clients/asyncssh_sftp_client.py +83 -0
- saviialib/libs/sftp_client/sftp_client.py +26 -0
- saviialib/libs/sftp_client/sftp_client_contract.py +13 -0
- saviialib/libs/sftp_client/types/sftp_client_types.py +24 -0
- saviialib/libs/sharepoint_client/__init__.py +2 -0
- saviialib/libs/sharepoint_client/clients/sharepoint_rest_api.py +31 -6
- saviialib/libs/sharepoint_client/sharepoint_client.py +25 -1
- saviialib/libs/sharepoint_client/sharepoint_client_contract.py +5 -0
- saviialib/libs/sharepoint_client/types/sharepoint_client_types.py +5 -0
- saviialib/libs/zero_dependency/utils/booleans_utils.py +2 -0
- saviialib/libs/zero_dependency/utils/datetime_utils.py +1 -1
- saviialib/libs/zero_dependency/utils/strings_utils.py +5 -0
- saviialib/services/backup/api.py +36 -0
- saviialib/services/backup/controllers/__init__.py +0 -0
- saviialib/services/{epii → backup}/controllers/types/__init__.py +1 -1
- saviialib/services/{epii → backup}/controllers/types/upload_backup_to_sharepoint_types.py +4 -2
- saviialib/services/{epii → backup}/controllers/upload_backup_to_sharepoint.py +9 -8
- saviialib/services/backup/use_cases/constants/upload_backup_to_sharepoint_constants.py +5 -0
- saviialib/services/{epii → backup}/use_cases/types/__init__.py +1 -1
- saviialib/services/{epii → backup}/use_cases/types/upload_backup_to_sharepoint_types.py +4 -2
- saviialib/services/backup/use_cases/upload_backup_to_sharepoint.py +474 -0
- saviialib/services/backup/utils/__init__.py +3 -0
- saviialib/services/backup/utils/upload_backup_to_sharepoint_utils.py +100 -0
- saviialib/services/netcamera/api.py +30 -0
- saviialib/services/netcamera/controllers/get_media_files.py +40 -0
- saviialib/services/netcamera/controllers/types/get_media_files_types.py +16 -0
- saviialib/services/netcamera/use_cases/get_media_files.py +76 -0
- saviialib/services/netcamera/use_cases/types/get_media_files_types.py +18 -0
- saviialib/services/shakes/__init__.py +0 -0
- saviialib/services/shakes/api.py +31 -0
- saviialib/services/shakes/controllers/get_miniseed_files.py +48 -0
- saviialib/services/shakes/controllers/types/get_miniseed_files_types.py +16 -0
- saviialib/services/shakes/use_cases/get_miniseed_files.py +79 -0
- saviialib/services/shakes/use_cases/types/get_miniseed_files_types.py +18 -0
- saviialib/services/shakes/use_cases/utils/get_miniseed_files_utils.py +11 -0
- saviialib/services/thies/__init__.py +0 -0
- saviialib/services/thies/api.py +42 -0
- saviialib/services/thies/constants/update_thies_data_constants.py +67 -0
- saviialib/services/{epii → thies}/controllers/types/update_thies_data_types.py +5 -4
- saviialib/services/{epii → thies}/controllers/update_thies_data.py +18 -6
- saviialib/services/thies/use_cases/components/create_thies_statistics_file.py +115 -0
- saviialib/services/thies/use_cases/components/thies_bp.py +442 -0
- saviialib/services/{epii → thies}/use_cases/types/update_thies_data_types.py +10 -2
- saviialib/services/thies/use_cases/update_thies_data.py +391 -0
- saviialib-1.6.0.dist-info/METADATA +126 -0
- saviialib-1.6.0.dist-info/RECORD +96 -0
- {saviialib-0.9.1.dist-info → saviialib-1.6.0.dist-info}/WHEEL +1 -1
- saviialib/services/epii/api.py +0 -80
- saviialib/services/epii/use_cases/constants/update_thies_data_constants.py +0 -5
- saviialib/services/epii/use_cases/constants/upload_backup_to_sharepoint_constants.py +0 -5
- saviialib/services/epii/use_cases/update_thies_data.py +0 -171
- saviialib/services/epii/use_cases/upload_backup_to_sharepoint.py +0 -241
- saviialib/services/epii/utils/__init__.py +0 -3
- saviialib/services/epii/utils/upload_backup_to_sharepoint_utils.py +0 -102
- saviialib-0.9.1.dist-info/METADATA +0 -120
- saviialib-0.9.1.dist-info/RECORD +0 -49
- /saviialib/{services/epii → libs/log_client/types}/__init__.py +0 -0
- /saviialib/services/{epii/controllers → backup}/__init__.py +0 -0
- /saviialib/services/{epii → thies}/utils/update_thies_data_utils.py +0 -0
- {saviialib-0.9.1.dist-info → saviialib-1.6.0.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
from typing import Any
|
|
2
|
-
|
|
3
|
-
from aiohttp import ClientError, ClientSession
|
|
2
|
+
import json
|
|
3
|
+
from aiohttp import ClientError, ClientSession, TCPConnector
|
|
4
4
|
from dotenv import load_dotenv
|
|
5
|
+
import ssl
|
|
6
|
+
import certifi
|
|
5
7
|
|
|
6
8
|
from saviialib.libs.sharepoint_client.sharepoint_client_contract import (
|
|
7
9
|
SharepointClientContract,
|
|
@@ -10,10 +12,12 @@ from saviialib.libs.sharepoint_client.types.sharepoint_client_types import (
|
|
|
10
12
|
SpListFilesArgs,
|
|
11
13
|
SpListFoldersArgs,
|
|
12
14
|
SpUploadFileArgs,
|
|
15
|
+
SpCreateFolderArgs,
|
|
13
16
|
SharepointClientInitArgs,
|
|
14
17
|
)
|
|
15
18
|
|
|
16
19
|
load_dotenv()
|
|
20
|
+
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
class SharepointRestAPI(SharepointClientContract):
|
|
@@ -50,7 +54,7 @@ class SharepointRestAPI(SharepointClientContract):
|
|
|
50
54
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
async with ClientSession() as session:
|
|
57
|
+
async with ClientSession(connector=TCPConnector(ssl=ssl_context)) as session:
|
|
54
58
|
# Load access token
|
|
55
59
|
response = await session.post(url, data=payload, headers=headers)
|
|
56
60
|
if response.status != 200:
|
|
@@ -74,8 +78,9 @@ class SharepointRestAPI(SharepointClientContract):
|
|
|
74
78
|
"Content-Type": "application/json",
|
|
75
79
|
}
|
|
76
80
|
self.base_url = f"{site_url}/sites/{self.site_name}/_api/"
|
|
81
|
+
connector = TCPConnector(ssl=ssl_context)
|
|
77
82
|
self.session = ClientSession(
|
|
78
|
-
headers=self.base_headers, base_url=self.base_url
|
|
83
|
+
headers=self.base_headers, base_url=self.base_url, connector=connector
|
|
79
84
|
)
|
|
80
85
|
return self
|
|
81
86
|
except ClientError as error:
|
|
@@ -104,10 +109,11 @@ class SharepointRestAPI(SharepointClientContract):
|
|
|
104
109
|
folder_relative_url = (
|
|
105
110
|
f"GetFolderByServerRelativeUrl('{args.folder_relative_url}')"
|
|
106
111
|
)
|
|
107
|
-
endpoint = f"web/{folder_relative_url}/
|
|
112
|
+
endpoint = f"web/{folder_relative_url}/Folders"
|
|
108
113
|
response = await self.session.get(endpoint.lstrip("/"))
|
|
109
114
|
response.raise_for_status()
|
|
110
|
-
|
|
115
|
+
response_json = await response.json()
|
|
116
|
+
return response_json
|
|
111
117
|
except ClientError as error:
|
|
112
118
|
raise ConnectionError(error) from error
|
|
113
119
|
|
|
@@ -133,3 +139,22 @@ class SharepointRestAPI(SharepointClientContract):
|
|
|
133
139
|
return await response.json()
|
|
134
140
|
except ClientError as error:
|
|
135
141
|
raise ConnectionError(error) from error
|
|
142
|
+
|
|
143
|
+
async def create_folder(self, args: SpCreateFolderArgs):
|
|
144
|
+
try:
|
|
145
|
+
# Load form digest value
|
|
146
|
+
form_digest_value = await self._load_form_digest_value()
|
|
147
|
+
headers = {
|
|
148
|
+
**self.base_headers,
|
|
149
|
+
"X-RequestDigest": form_digest_value,
|
|
150
|
+
}
|
|
151
|
+
body = {"ServerRelativeUrl": f"{args.folder_relative_url}"}
|
|
152
|
+
endpoint = "web/folders"
|
|
153
|
+
response = await self.session.post(
|
|
154
|
+
endpoint.lstrip("/"), data=json.dumps(body), headers=headers
|
|
155
|
+
)
|
|
156
|
+
response.raise_for_status()
|
|
157
|
+
response_json = await response.json()
|
|
158
|
+
return response_json
|
|
159
|
+
except ClientError as error:
|
|
160
|
+
raise ConnectionError(error) from error
|
|
@@ -5,6 +5,7 @@ from .types.sharepoint_client_types import (
|
|
|
5
5
|
SpListFilesArgs,
|
|
6
6
|
SpListFoldersArgs,
|
|
7
7
|
SpUploadFileArgs,
|
|
8
|
+
SpCreateFolderArgs,
|
|
8
9
|
)
|
|
9
10
|
|
|
10
11
|
|
|
@@ -18,6 +19,26 @@ class SharepointClient(SharepointClientContract):
|
|
|
18
19
|
elif args.client_name == "sharepoint_rest_api":
|
|
19
20
|
self.client_obj = SharepointRestAPI(args)
|
|
20
21
|
|
|
22
|
+
@property
|
|
23
|
+
def tenant_id(self):
|
|
24
|
+
return self.client_obj.tenant_id
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def tenant_name(self):
|
|
28
|
+
return self.client_obj.tenant_name
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def site_name(self):
|
|
32
|
+
return self.client_obj.site_name
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def client_id(self):
|
|
36
|
+
return self.client_obj.client_id
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def client_secret(self):
|
|
40
|
+
return self.client_obj.client_secret
|
|
41
|
+
|
|
21
42
|
async def __aenter__(self):
|
|
22
43
|
return await self.client_obj.__aenter__()
|
|
23
44
|
|
|
@@ -28,7 +49,10 @@ class SharepointClient(SharepointClientContract):
|
|
|
28
49
|
return await self.client_obj.list_files(args)
|
|
29
50
|
|
|
30
51
|
async def list_folders(self, args: SpListFoldersArgs) -> list:
|
|
31
|
-
return await self.client_obj.
|
|
52
|
+
return await self.client_obj.list_folders(args)
|
|
32
53
|
|
|
33
54
|
async def upload_file(self, args: SpUploadFileArgs) -> dict:
|
|
34
55
|
return await self.client_obj.upload_file(args)
|
|
56
|
+
|
|
57
|
+
async def create_folder(self, args: SpCreateFolderArgs) -> dict:
|
|
58
|
+
return await self.client_obj.create_folder(args)
|
|
@@ -4,6 +4,7 @@ from .types.sharepoint_client_types import (
|
|
|
4
4
|
SpListFilesArgs,
|
|
5
5
|
SpListFoldersArgs,
|
|
6
6
|
SpUploadFileArgs,
|
|
7
|
+
SpCreateFolderArgs,
|
|
7
8
|
)
|
|
8
9
|
|
|
9
10
|
|
|
@@ -19,3 +20,7 @@ class SharepointClientContract(ABC):
|
|
|
19
20
|
@abstractmethod
|
|
20
21
|
async def upload_file(self, args: SpUploadFileArgs) -> dict:
|
|
21
22
|
pass
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
async def create_folder(self, args: SpCreateFolderArgs) -> dict:
|
|
26
|
+
pass
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
from .controllers.upload_backup_to_sharepoint import (
|
|
4
|
+
UploadBackupToSharepointControllerInput,
|
|
5
|
+
)
|
|
6
|
+
from .controllers.upload_backup_to_sharepoint import UploadBackupToSharepointController
|
|
7
|
+
from saviialib.general_types.api.saviia_backup_api_types import SaviiaBackupConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SaviiaBackupAPI:
|
|
11
|
+
"""
|
|
12
|
+
EpiiAPI is a service class that provides methods to interact with Patagonia Center system.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, config: SaviiaBackupConfig):
|
|
16
|
+
self.config = config
|
|
17
|
+
|
|
18
|
+
async def upload_backup_to_sharepoint(
|
|
19
|
+
self, local_backup_source_path: str, sharepoint_destination_path: str
|
|
20
|
+
) -> Dict[str, Any]:
|
|
21
|
+
"""Migrate a backup folder from Home assistant to Sharepoint directory.
|
|
22
|
+
Args:
|
|
23
|
+
local_backup_source_path (str): Local path to backup.
|
|
24
|
+
Returns:
|
|
25
|
+
response (dict): A dictionary containing the response from the upload operation.
|
|
26
|
+
This dictionary will typically include information about the success or
|
|
27
|
+
failure of the upload, as well as any relevant metadata.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
controller = UploadBackupToSharepointController(
|
|
31
|
+
UploadBackupToSharepointControllerInput(
|
|
32
|
+
self.config, local_backup_source_path, sharepoint_destination_path
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
response = await controller.execute()
|
|
36
|
+
return response.__dict__
|
|
File without changes
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
2
|
from typing import Dict
|
|
3
3
|
|
|
4
|
-
from saviialib.general_types.api.
|
|
4
|
+
from saviialib.general_types.api.saviia_backup_api_types import SaviiaBackupConfig
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
@dataclass
|
|
8
8
|
class UploadBackupToSharepointControllerInput:
|
|
9
|
-
config:
|
|
9
|
+
config: SaviiaBackupConfig
|
|
10
|
+
local_backup_source_path: str
|
|
11
|
+
sharepoint_destination_path: str
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
@dataclass
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from http import HTTPStatus
|
|
2
|
-
from saviialib.general_types.api.
|
|
2
|
+
from saviialib.general_types.api.saviia_api_types import SharepointConfig
|
|
3
3
|
|
|
4
|
-
from saviialib.general_types.error_types.api.
|
|
4
|
+
from saviialib.general_types.error_types.api.saviia_api_error_types import (
|
|
5
5
|
BackupUploadError,
|
|
6
6
|
BackupSourcePathError,
|
|
7
7
|
BackupEmptyError,
|
|
@@ -10,14 +10,14 @@ from saviialib.general_types.error_types.common.common_types import (
|
|
|
10
10
|
EmptyDataError,
|
|
11
11
|
SharepointClientError,
|
|
12
12
|
)
|
|
13
|
-
from saviialib.services.
|
|
13
|
+
from saviialib.services.backup.controllers.types.upload_backup_to_sharepoint_types import (
|
|
14
14
|
UploadBackupToSharepointControllerInput,
|
|
15
15
|
UploadBackupToSharepointControllerOutput,
|
|
16
16
|
)
|
|
17
|
-
from saviialib.services.
|
|
17
|
+
from saviialib.services.backup.use_cases.types.upload_backup_to_sharepoint_types import (
|
|
18
18
|
UploadBackupToSharepointUseCaseInput,
|
|
19
19
|
)
|
|
20
|
-
from saviialib.services.
|
|
20
|
+
from saviialib.services.backup.use_cases.upload_backup_to_sharepoint import (
|
|
21
21
|
UploadBackupToSharepointUsecase,
|
|
22
22
|
)
|
|
23
23
|
|
|
@@ -33,8 +33,9 @@ class UploadBackupToSharepointController:
|
|
|
33
33
|
sharepoint_tenant_name=input.config.sharepoint_tenant_name,
|
|
34
34
|
sharepoint_tenant_id=input.config.sharepoint_tenant_id,
|
|
35
35
|
),
|
|
36
|
-
local_backup_source_path=input.
|
|
37
|
-
|
|
36
|
+
local_backup_source_path=input.local_backup_source_path,
|
|
37
|
+
sharepoint_destination_path=input.sharepoint_destination_path,
|
|
38
|
+
logger=input.config.logger,
|
|
38
39
|
)
|
|
39
40
|
)
|
|
40
41
|
|
|
@@ -44,7 +45,7 @@ class UploadBackupToSharepointController:
|
|
|
44
45
|
return UploadBackupToSharepointControllerOutput(
|
|
45
46
|
message="Local backup was migrated successfully",
|
|
46
47
|
status=HTTPStatus.OK.value,
|
|
47
|
-
metadata={"data": data},
|
|
48
|
+
metadata={"data": data}, # type: ignore
|
|
48
49
|
)
|
|
49
50
|
except EmptyDataError:
|
|
50
51
|
return UploadBackupToSharepointControllerOutput(
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
|
-
from saviialib.general_types.api.
|
|
2
|
+
from saviialib.general_types.api.saviia_api_types import SharepointConfig
|
|
3
|
+
from logging import Logger
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
@dataclass
|
|
6
7
|
class UploadBackupToSharepointUseCaseInput:
|
|
7
8
|
sharepoint_config: SharepointConfig
|
|
8
9
|
local_backup_source_path: str
|
|
9
|
-
|
|
10
|
+
sharepoint_destination_path: str
|
|
11
|
+
logger: Logger
|