rara-tools 0.0.2__tar.gz → 0.0.4__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.

Files changed (22) hide show
  1. {rara_tools-0.0.2/rara_tools.egg-info → rara_tools-0.0.4}/PKG-INFO +2 -2
  2. rara_tools-0.0.4/VERSION +1 -0
  3. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools/s3.py +12 -8
  4. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools/task_reporter.py +36 -10
  5. {rara_tools-0.0.2 → rara_tools-0.0.4/rara_tools.egg-info}/PKG-INFO +2 -2
  6. rara_tools-0.0.2/VERSION +0 -1
  7. {rara_tools-0.0.2 → rara_tools-0.0.4}/LICENSE.md +0 -0
  8. {rara_tools-0.0.2 → rara_tools-0.0.4}/README.md +0 -0
  9. {rara_tools-0.0.2 → rara_tools-0.0.4}/pyproject.toml +0 -0
  10. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools/decorators.py +0 -0
  11. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools/elastic.py +0 -0
  12. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools/exceptions.py +0 -0
  13. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools.egg-info/SOURCES.txt +0 -0
  14. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools.egg-info/dependency_links.txt +0 -0
  15. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools.egg-info/requires.txt +0 -0
  16. {rara_tools-0.0.2 → rara_tools-0.0.4}/rara_tools.egg-info/top_level.txt +0 -0
  17. {rara_tools-0.0.2 → rara_tools-0.0.4}/requirements.txt +0 -0
  18. {rara_tools-0.0.2 → rara_tools-0.0.4}/setup.cfg +0 -0
  19. {rara_tools-0.0.2 → rara_tools-0.0.4}/tests/test_elastic.py +0 -0
  20. {rara_tools-0.0.2 → rara_tools-0.0.4}/tests/test_s3_exceptions.py +0 -0
  21. {rara_tools-0.0.2 → rara_tools-0.0.4}/tests/test_s3_file_operations.py +0 -0
  22. {rara_tools-0.0.2 → rara_tools-0.0.4}/tests/test_task_reporter.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: rara-tools
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -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:
@@ -42,12 +45,13 @@ class S3Files:
42
45
  raise S3InputException(f"File '{file_path}' does not exist in file system!")
43
46
  return self.minio_client.fput_object(self.bucket, s3_path_name, file_path)
44
47
 
45
- def list(self, prefix: Optional[str] = "") -> List:
46
- """Lists all available files in S3 bucket.
48
+ def list(self, prefix: Optional[str] = "", recursive: Optional[bool] = True) -> List:
49
+ """Lists all available directories or files in S3 bucket.
47
50
  :param: prefix str: Limits the listing to a given prefix.
51
+ :param: recursive bool: List files recursively.
48
52
  :return: List of file paths in S3.
49
53
  """
50
- list_of_objects = self.minio_client.list_objects(self.bucket, prefix=prefix, recursive=True)
54
+ list_of_objects = self.minio_client.list_objects(self.bucket, prefix=prefix, recursive=recursive)
51
55
  list_of_objects = [o.object_name for o in list_of_objects]
52
56
  return list_of_objects
53
57
 
@@ -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
- self,
15
- api_url: str,
16
- api_token: str,
17
- api_timeout: Optional[int] = 10,
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}/tasks/{task_id}/"
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 = self.api_headers,
44
- json = content,
45
- timeout = self.api_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
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: rara-tools
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
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