rara-tools 0.0.2__tar.gz → 0.0.3__tar.gz
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 rara-tools might be problematic. Click here for more details.
- {rara_tools-0.0.2/rara_tools.egg-info → rara_tools-0.0.3}/PKG-INFO +2 -2
- rara_tools-0.0.3/VERSION +1 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools/s3.py +8 -5
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools/task_reporter.py +36 -10
- {rara_tools-0.0.2 → rara_tools-0.0.3/rara_tools.egg-info}/PKG-INFO +2 -2
- rara_tools-0.0.2/VERSION +0 -1
- {rara_tools-0.0.2 → rara_tools-0.0.3}/LICENSE.md +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/README.md +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/pyproject.toml +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools/decorators.py +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools/elastic.py +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools/exceptions.py +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools.egg-info/SOURCES.txt +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools.egg-info/dependency_links.txt +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools.egg-info/requires.txt +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/rara_tools.egg-info/top_level.txt +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/requirements.txt +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/setup.cfg +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/tests/test_elastic.py +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/tests/test_s3_exceptions.py +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/tests/test_s3_file_operations.py +0 -0
- {rara_tools-0.0.2 → rara_tools-0.0.3}/tests/test_task_reporter.py +0 -0
rara_tools-0.0.3/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.3
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import uuid
|
|
3
|
-
from typing import Optional, List, Generator
|
|
3
|
+
from typing import Optional, List, Generator, Any
|
|
4
|
+
|
|
4
5
|
from minio import Minio
|
|
5
6
|
|
|
6
7
|
from .exceptions import S3InitException, S3ConnectionException, S3InputException
|
|
@@ -15,8 +16,9 @@ class S3Files:
|
|
|
15
16
|
url: Optional[str] = None,
|
|
16
17
|
access_key: Optional[str] = None,
|
|
17
18
|
secret_key: Optional[str] = None,
|
|
18
|
-
bucket: Optional[str] = None
|
|
19
|
-
|
|
19
|
+
bucket: Optional[str] = None,
|
|
20
|
+
**minio_kwargs: dict[str, Any],
|
|
21
|
+
):
|
|
20
22
|
if not url:
|
|
21
23
|
raise S3InitException("S3 URL not set!")
|
|
22
24
|
if not access_key:
|
|
@@ -24,12 +26,13 @@ class S3Files:
|
|
|
24
26
|
if not secret_key:
|
|
25
27
|
raise S3InitException("S3 secret key not set!")
|
|
26
28
|
if not bucket:
|
|
27
|
-
raise S3InitException("Bucket not set!")
|
|
29
|
+
raise S3InitException("Bucket not set!")
|
|
28
30
|
self.bucket = bucket
|
|
29
31
|
self.minio_client = Minio(
|
|
30
32
|
url,
|
|
31
33
|
access_key=access_key,
|
|
32
|
-
secret_key=secret_key
|
|
34
|
+
secret_key=secret_key,
|
|
35
|
+
**minio_kwargs
|
|
33
36
|
)
|
|
34
37
|
# Check S3 connection
|
|
35
38
|
try:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import requests
|
|
2
1
|
from typing import Optional
|
|
3
2
|
|
|
3
|
+
import requests
|
|
4
|
+
|
|
4
5
|
from .exceptions import TaskReporterException
|
|
5
6
|
|
|
6
7
|
|
|
@@ -10,11 +11,12 @@ class TaskReporter:
|
|
|
10
11
|
* running instance of Core API,
|
|
11
12
|
* Core API access token with sufficient privileges.
|
|
12
13
|
"""
|
|
14
|
+
|
|
13
15
|
def __init__(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
self,
|
|
17
|
+
api_url: str,
|
|
18
|
+
api_token: str,
|
|
19
|
+
api_timeout: Optional[int] = 10,
|
|
18
20
|
):
|
|
19
21
|
# Remove possible trailing / from API url.
|
|
20
22
|
self.api_url = api_url.rstrip("/")
|
|
@@ -35,14 +37,26 @@ class TaskReporter:
|
|
|
35
37
|
return True
|
|
36
38
|
return False
|
|
37
39
|
|
|
38
|
-
def _perform_patch(self, content: dict, task_id: int):
|
|
39
|
-
url = f"{self.api_url}/
|
|
40
|
+
def _perform_patch(self, content: dict, task_id: int, tasks_endpoint: str = "tasks"):
|
|
41
|
+
url = f"{self.api_url}/{tasks_endpoint}/{task_id}/"
|
|
40
42
|
try:
|
|
41
43
|
return requests.patch(
|
|
42
44
|
url,
|
|
43
|
-
headers
|
|
44
|
-
json
|
|
45
|
-
timeout
|
|
45
|
+
headers=self.api_headers,
|
|
46
|
+
json=content,
|
|
47
|
+
timeout=self.api_timeout
|
|
48
|
+
)
|
|
49
|
+
except Exception as e:
|
|
50
|
+
raise TaskReporterException(f"Error patching document: {e}")
|
|
51
|
+
|
|
52
|
+
def _perform_status_update(self, content: dict, task_id: int, tasks_endpoint: str = "tasks", action_endpoint: str = "update_status"):
|
|
53
|
+
url = f"{self.api_url}/{tasks_endpoint}/{task_id}/{action_endpoint}/"
|
|
54
|
+
try:
|
|
55
|
+
return requests.post(
|
|
56
|
+
url,
|
|
57
|
+
headers=self.api_headers,
|
|
58
|
+
json=content,
|
|
59
|
+
timeout=self.api_timeout
|
|
46
60
|
)
|
|
47
61
|
except Exception as e:
|
|
48
62
|
raise TaskReporterException(f"Error patching document: {e}")
|
|
@@ -57,3 +71,15 @@ class TaskReporter:
|
|
|
57
71
|
if response.status_code not in (200, 204):
|
|
58
72
|
raise TaskReporterException(f"Error code from Core API: {response.status_code}")
|
|
59
73
|
return response
|
|
74
|
+
|
|
75
|
+
def update_status(self, key: str, task_id: int, **status_options):
|
|
76
|
+
"""Updates the status of sub-tasks to Core API.
|
|
77
|
+
:param: key: Since task statuses are Many-to-Many a normal patch won't work, hence we filter the status we want through the key.
|
|
78
|
+
:param: status_options: Keys & values to update in the status model.
|
|
79
|
+
:return: Response object.
|
|
80
|
+
"""
|
|
81
|
+
content = {"key": key, **status_options}
|
|
82
|
+
response = self._perform_status_update(content, task_id)
|
|
83
|
+
if response.status_code not in (200, 204):
|
|
84
|
+
raise TaskReporterException(f"Error code from Core API: {response.status_code}")
|
|
85
|
+
return response
|
rara_tools-0.0.2/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.0.2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|