rara-tools 0.0.1__py3-none-any.whl → 0.0.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 rara-tools might be problematic. Click here for more details.
- rara_tools/elastic.py +12 -9
- rara_tools/s3.py +10 -8
- rara_tools-0.0.2.dist-info/METADATA +175 -0
- rara_tools-0.0.2.dist-info/RECORD +10 -0
- rara_tools-0.0.1.dist-info/METADATA +0 -21
- rara_tools-0.0.1.dist-info/RECORD +0 -10
- {rara_tools-0.0.1.dist-info → rara_tools-0.0.2.dist-info}/LICENSE.md +0 -0
- {rara_tools-0.0.1.dist-info → rara_tools-0.0.2.dist-info}/WHEEL +0 -0
- {rara_tools-0.0.1.dist-info → rara_tools-0.0.2.dist-info}/top_level.txt +0 -0
rara_tools/elastic.py
CHANGED
|
@@ -8,7 +8,7 @@ from .decorators import _elastic_connection
|
|
|
8
8
|
class KataElastic:
|
|
9
9
|
"""A class to manage all required Elasticsearch operations for Kata.
|
|
10
10
|
"""
|
|
11
|
-
def __init__(self, elasticsearch_url, timeout: Optional[int] = None):
|
|
11
|
+
def __init__(self, elasticsearch_url: str, timeout: Optional[int] = None):
|
|
12
12
|
self.timeout = timeout
|
|
13
13
|
self.elasticsearch_url = elasticsearch_url
|
|
14
14
|
self.elasticsearch = Elasticsearch(self.elasticsearch_url, request_timeout=self.timeout)
|
|
@@ -16,7 +16,7 @@ class KataElastic:
|
|
|
16
16
|
@_elastic_connection
|
|
17
17
|
def check(self) -> bool:
|
|
18
18
|
"""Checks Elasticsearch connection.
|
|
19
|
-
:return: bool: Elasticsearch
|
|
19
|
+
:return: bool: Elasticsearch alive or dead.
|
|
20
20
|
"""
|
|
21
21
|
if self.elasticsearch.ping():
|
|
22
22
|
return True
|
|
@@ -31,7 +31,7 @@ class KataElastic:
|
|
|
31
31
|
settings: Optional[dict] = None
|
|
32
32
|
) -> Dict:
|
|
33
33
|
"""Creates empty index.
|
|
34
|
-
:param: index str: Name of the
|
|
34
|
+
:param: index str: Name of the index to create.
|
|
35
35
|
:param: shards int: Number of shards for the index.
|
|
36
36
|
:param: replicas int: Number of replicas of the index.
|
|
37
37
|
:param: settings dict: Overwrite settings for the index.
|
|
@@ -43,22 +43,24 @@ class KataElastic:
|
|
|
43
43
|
return self.elasticsearch.indices.create(index=index, settings=body)
|
|
44
44
|
|
|
45
45
|
@_elastic_connection
|
|
46
|
-
def delete_index(self, index: str, ignore: Optional[bool] = True) ->
|
|
46
|
+
def delete_index(self, index: str, ignore: Optional[bool] = True) -> Dict:
|
|
47
47
|
"""Deletes index.
|
|
48
48
|
:param: index str: Name of the index to be deleted.
|
|
49
49
|
:param: ignore bool: Ignore errors because of closed/deleted index.
|
|
50
|
+
:return: Dict of Elastic's acknowledgement of the action.
|
|
50
51
|
"""
|
|
51
52
|
response = self.elasticsearch.indices.delete(index=index, ignore_unavailable=ignore)
|
|
52
53
|
return response
|
|
53
54
|
|
|
54
55
|
@_elastic_connection
|
|
55
|
-
def delete_document(self,
|
|
56
|
+
def delete_document(self, index: str, document_id: str) -> Dict:
|
|
56
57
|
"""Deletes document fom index.
|
|
57
58
|
:param: document_id str: ID of the document to be deleted.
|
|
58
59
|
:param: index str: Index where the document is to be found.
|
|
59
60
|
:param: ignore bool: Ignore errors because of closed/deleted index.
|
|
61
|
+
:return: Dict of Elastic's acknowledgement of the action.
|
|
60
62
|
"""
|
|
61
|
-
response = self.elasticsearch.delete(id=document_id, index=index
|
|
63
|
+
response = self.elasticsearch.delete(id=document_id, index=index)
|
|
62
64
|
return response
|
|
63
65
|
|
|
64
66
|
@_elastic_connection
|
|
@@ -67,12 +69,13 @@ class KataElastic:
|
|
|
67
69
|
:param: index str: Index that document will be indexed into.
|
|
68
70
|
:param: body dict: Document body.
|
|
69
71
|
:param: document_id str: Optional id for the document. Is generated automatically if None.
|
|
72
|
+
:return: Dict of Elastic's acknowledgement of the action.
|
|
70
73
|
"""
|
|
71
74
|
if document_id:
|
|
72
|
-
|
|
75
|
+
indexed = self.elasticsearch.index(index=index, id=document_id, body=body)
|
|
73
76
|
else:
|
|
74
|
-
|
|
75
|
-
return
|
|
77
|
+
indexed = self.elasticsearch.index(index=index, body=body)
|
|
78
|
+
return indexed
|
|
76
79
|
|
|
77
80
|
@_elastic_connection
|
|
78
81
|
def get_documents_by_key(self, index: str, document_key: str) -> List:
|
rara_tools/s3.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import uuid
|
|
3
|
-
from typing import Optional
|
|
3
|
+
from typing import Optional, List, Generator
|
|
4
4
|
from minio import Minio
|
|
5
5
|
|
|
6
6
|
from .exceptions import S3InitException, S3ConnectionException, S3InputException
|
|
@@ -42,7 +42,7 @@ class S3Files:
|
|
|
42
42
|
raise S3InputException(f"File '{file_path}' does not exist in file system!")
|
|
43
43
|
return self.minio_client.fput_object(self.bucket, s3_path_name, file_path)
|
|
44
44
|
|
|
45
|
-
def list(self, prefix: Optional[str] = ""):
|
|
45
|
+
def list(self, prefix: Optional[str] = "") -> List:
|
|
46
46
|
"""Lists all available files in S3 bucket.
|
|
47
47
|
:param: prefix str: Limits the listing to a given prefix.
|
|
48
48
|
:return: List of file paths in S3.
|
|
@@ -51,16 +51,18 @@ class S3Files:
|
|
|
51
51
|
list_of_objects = [o.object_name for o in list_of_objects]
|
|
52
52
|
return list_of_objects
|
|
53
53
|
|
|
54
|
-
def delete(self, path: str):
|
|
54
|
+
def delete(self, path: str) -> bool:
|
|
55
55
|
"""Deletes file in S3.
|
|
56
56
|
:param: path str: Path of the file in S3 to be deleted.
|
|
57
|
+
:return: True.
|
|
57
58
|
"""
|
|
58
59
|
list_of_objects = self.minio_client.list_objects(self.bucket, prefix=path, recursive=True)
|
|
59
60
|
list_of_objects = [o.object_name for o in list_of_objects]
|
|
60
61
|
for path_to_delete in list_of_objects:
|
|
61
62
|
self.minio_client.remove_object(self.bucket, path_to_delete)
|
|
63
|
+
return True
|
|
62
64
|
|
|
63
|
-
def download(self, path: str, download_dir: Optional[str] = "."):
|
|
65
|
+
def download(self, path: str, download_dir: Optional[str] = ".") -> Generator[str, str, str]:
|
|
64
66
|
"""Downloads file or folder from S3.
|
|
65
67
|
:param: path str: Path to the file or folder in S3.
|
|
66
68
|
:param: download_dir str: Directory to download the files and folders into.
|
|
@@ -72,26 +74,26 @@ class S3Files:
|
|
|
72
74
|
self.minio_client.fget_object(self.bucket, minio_object.object_name, full_path)
|
|
73
75
|
yield full_path
|
|
74
76
|
|
|
75
|
-
def upload(self, path: str, prefix: Optional[str] = ""):
|
|
77
|
+
def upload(self, path: str, prefix: Optional[str] = "") -> str:
|
|
76
78
|
"""Uploads file or folder to S3 bucket.
|
|
77
79
|
:param: path str: Path to the file to upload in local file system.
|
|
78
80
|
:param: prefix str: Optional prefix for S3 path.
|
|
79
81
|
:returns: File path of the uploaded file or folder in S3.
|
|
80
82
|
"""
|
|
81
|
-
path_name = os.path.split(path)[-1]
|
|
82
83
|
# Manage directories
|
|
83
84
|
if os.path.isdir(path):
|
|
84
85
|
s3_path_prefix = f"{prefix}{uuid.uuid4().hex}"
|
|
85
86
|
for root, _, files in os.walk(path):
|
|
86
87
|
for file in files:
|
|
88
|
+
relative_prefix = root.removeprefix(path).lstrip("/")
|
|
87
89
|
file_path = os.path.join(root, file)
|
|
88
90
|
extension = file.split(".")[-1]
|
|
89
|
-
|
|
90
|
-
s3_path_name = os.path.join(s3_path_prefix, s3_file_name)
|
|
91
|
+
s3_path_name = os.path.join(s3_path_prefix, relative_prefix, file)
|
|
91
92
|
self._put_file(file_path, s3_path_name)
|
|
92
93
|
return s3_path_prefix
|
|
93
94
|
# Manage single files
|
|
94
95
|
else:
|
|
96
|
+
path_name = os.path.split(path)[-1]
|
|
95
97
|
extension = path_name.split(".")[-1]
|
|
96
98
|
s3_path_name = f"{prefix}{uuid.uuid4().hex}.{extension}"
|
|
97
99
|
self._put_file(path, s3_path_name)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rara-tools
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Tools to support Kata's work.
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Requires-Dist: elasticsearch==8.*
|
|
14
|
+
Requires-Dist: elasticsearch_dsl==8.*
|
|
15
|
+
Requires-Dist: minio==7.*
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Provides-Extra: testing
|
|
18
|
+
Requires-Dist: pytest>=8.0; extra == "testing"
|
|
19
|
+
Requires-Dist: pytest-order; extra == "testing"
|
|
20
|
+
|
|
21
|
+
# RaRa Tools
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+

|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
**`rara-tools`** is a Python library containing various generic tools used by components of Kata.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ✨ Features
|
|
32
|
+
|
|
33
|
+
- Elasticsearch index & document operations
|
|
34
|
+
- S3 file management operations
|
|
35
|
+
- Task reporting to Core API
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## ⚡ Quick Start
|
|
39
|
+
|
|
40
|
+
Get started with `rara-tools` in just a few steps:
|
|
41
|
+
|
|
42
|
+
1. **Install the Package**
|
|
43
|
+
Ensure you're using Python 3.10 or above, then run:
|
|
44
|
+
```bash
|
|
45
|
+
pip install rara-tools
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. **Import and Use**
|
|
49
|
+
Example usage to download a folder from S3:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from rara_tools.s3 import S3Files
|
|
53
|
+
|
|
54
|
+
s3 = S3Files(
|
|
55
|
+
url="your-s3-address",
|
|
56
|
+
access_key = "xxx",
|
|
57
|
+
secret_key = "yyy",
|
|
58
|
+
bucket = "my-sad-bucket"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
s3.download("my-folder-in-s3")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## ⚙️ Installation Guide
|
|
67
|
+
|
|
68
|
+
Follow the steps below to install the `rara-tools` package, either via `pip` or locally.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### Installation via `pip`
|
|
73
|
+
|
|
74
|
+
<details><summary>Click to expand</summary>
|
|
75
|
+
|
|
76
|
+
1. **Set Up Your Python Environment**
|
|
77
|
+
Create or activate a Python environment using Python **3.10** or above.
|
|
78
|
+
|
|
79
|
+
2. **Install the Package**
|
|
80
|
+
Run the following command:
|
|
81
|
+
```bash
|
|
82
|
+
pip install rara-tools
|
|
83
|
+
```
|
|
84
|
+
</details>
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### Local Installation
|
|
89
|
+
|
|
90
|
+
Follow these steps to install the `rara-tools` package locally:
|
|
91
|
+
|
|
92
|
+
<details><summary>Click to expand</summary>
|
|
93
|
+
|
|
94
|
+
1. **Clone the Repository**
|
|
95
|
+
Clone the repository and navigate into it:
|
|
96
|
+
```bash
|
|
97
|
+
git clone <repository-url>
|
|
98
|
+
cd <repository-directory>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
2. **Set Up Python Environment**
|
|
102
|
+
Create or activate a Python environment using Python 3.10 or above. E.g:
|
|
103
|
+
```bash
|
|
104
|
+
conda create -n py310 python==3.10
|
|
105
|
+
conda activate py310
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
3. **Install Build Package**
|
|
109
|
+
Install the `build` package to enable local builds:
|
|
110
|
+
```bash
|
|
111
|
+
pip install build
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
4. **Build the Package**
|
|
115
|
+
Run the following command inside the repository:
|
|
116
|
+
```bash
|
|
117
|
+
python -m build
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
5. **Install the Package**
|
|
121
|
+
Install the built package locally:
|
|
122
|
+
```bash
|
|
123
|
+
pip install .
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
</details>
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 🚀 Testing Guide
|
|
131
|
+
|
|
132
|
+
Follow these steps to test the `rara-tools` package.
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### How to Test
|
|
136
|
+
|
|
137
|
+
<details><summary>Click to expand</summary>
|
|
138
|
+
|
|
139
|
+
1. **Clone the Repository**
|
|
140
|
+
Clone the repository and navigate into it:
|
|
141
|
+
```bash
|
|
142
|
+
git clone <repository-url>
|
|
143
|
+
cd <repository-directory>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
2. **Set Up Python Environment**
|
|
147
|
+
Create or activate a Python environment using Python 3.10 or above.
|
|
148
|
+
|
|
149
|
+
3. **Install Build Package**
|
|
150
|
+
Install the `build` package:
|
|
151
|
+
```bash
|
|
152
|
+
pip install build
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
4. **Build the Package**
|
|
156
|
+
Build the package inside the repository:
|
|
157
|
+
```bash
|
|
158
|
+
python -m build
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
5. **Install with Testing Dependencies**
|
|
162
|
+
Install the package along with its testing dependencies:
|
|
163
|
+
```bash
|
|
164
|
+
pip install .[testing]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
6. **Run Tests**
|
|
168
|
+
Run the test suite from the repository root:
|
|
169
|
+
```bash
|
|
170
|
+
python -m pytest -v tests
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
</details>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
rara_tools/decorators.py,sha256=rYDk5CEHhCZvqeFaHku8qLMv7G7NTMWppHwLg3ZeVj4,2186
|
|
2
|
+
rara_tools/elastic.py,sha256=MVqai6wDQlDQeHQzAKsRpxOchI29y3W1UiridgfH6d4,3718
|
|
3
|
+
rara_tools/exceptions.py,sha256=FtuHG-2snaEfADA25HjjutGNQzNo6sTdSfqk9VrzOuE,374
|
|
4
|
+
rara_tools/s3.py,sha256=XHTiPBdOrh9naViEI-AEISjQitSiBOR44onJz6a1ltk,4261
|
|
5
|
+
rara_tools/task_reporter.py,sha256=g2Q9y35_mp2G5G4dEiM32otrreg6rJLB2Oi66HSDzJA,2016
|
|
6
|
+
rara_tools-0.0.2.dist-info/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
|
|
7
|
+
rara_tools-0.0.2.dist-info/METADATA,sha256=m-JCi2fkPmjmm9tUg69mfQfZ4gjOZP8bdH00gPZkDJ0,3820
|
|
8
|
+
rara_tools-0.0.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
9
|
+
rara_tools-0.0.2.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
|
|
10
|
+
rara_tools-0.0.2.dist-info/RECORD,,
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: rara-tools
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: Tools to support Kata's work.
|
|
5
|
-
Classifier: Programming Language :: Python :: 3
|
|
6
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
7
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
-
Classifier: Intended Audience :: Science/Research
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.md
|
|
13
|
-
Requires-Dist: elasticsearch==8.*
|
|
14
|
-
Requires-Dist: elasticsearch_dsl==8.*
|
|
15
|
-
Requires-Dist: minio==7.*
|
|
16
|
-
Requires-Dist: requests
|
|
17
|
-
Provides-Extra: testing
|
|
18
|
-
Requires-Dist: pytest>=8.0; extra == "testing"
|
|
19
|
-
Requires-Dist: pytest-order; extra == "testing"
|
|
20
|
-
|
|
21
|
-
# rara-tools
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
rara_tools/decorators.py,sha256=rYDk5CEHhCZvqeFaHku8qLMv7G7NTMWppHwLg3ZeVj4,2186
|
|
2
|
-
rara_tools/elastic.py,sha256=rKQCekqzmPqqIpMuJL4ooieH_Oy1yzNEeCrdNxKephw,3578
|
|
3
|
-
rara_tools/exceptions.py,sha256=FtuHG-2snaEfADA25HjjutGNQzNo6sTdSfqk9VrzOuE,374
|
|
4
|
-
rara_tools/s3.py,sha256=AmohpirzmplO12wzhsNKFXTZq7hMV-dgymsgcHu8h-8,4132
|
|
5
|
-
rara_tools/task_reporter.py,sha256=g2Q9y35_mp2G5G4dEiM32otrreg6rJLB2Oi66HSDzJA,2016
|
|
6
|
-
rara_tools-0.0.1.dist-info/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
|
|
7
|
-
rara_tools-0.0.1.dist-info/METADATA,sha256=ch4-sgZX5n231Rz8LbOtW3cDhK6XpVGQB-uuuy0PMI4,688
|
|
8
|
-
rara_tools-0.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
9
|
-
rara_tools-0.0.1.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
|
|
10
|
-
rara_tools-0.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|