naeural-client 2.0.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.
- naeural_client/__init__.py +13 -0
- naeural_client/_ver.py +13 -0
- naeural_client/base/__init__.py +6 -0
- naeural_client/base/distributed_custom_code_presets.py +44 -0
- naeural_client/base/generic_session.py +1763 -0
- naeural_client/base/instance.py +616 -0
- naeural_client/base/payload/__init__.py +1 -0
- naeural_client/base/payload/payload.py +66 -0
- naeural_client/base/pipeline.py +1499 -0
- naeural_client/base/plugin_template.py +5209 -0
- naeural_client/base/responses.py +209 -0
- naeural_client/base/transaction.py +157 -0
- naeural_client/base_decentra_object.py +143 -0
- naeural_client/bc/__init__.py +3 -0
- naeural_client/bc/base.py +1046 -0
- naeural_client/bc/chain.py +0 -0
- naeural_client/bc/ec.py +324 -0
- naeural_client/certs/__init__.py +0 -0
- naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt +22 -0
- naeural_client/code_cheker/__init__.py +1 -0
- naeural_client/code_cheker/base.py +520 -0
- naeural_client/code_cheker/checker.py +294 -0
- naeural_client/comm/__init__.py +2 -0
- naeural_client/comm/amqp_wrapper.py +338 -0
- naeural_client/comm/mqtt_wrapper.py +539 -0
- naeural_client/const/README.md +3 -0
- naeural_client/const/__init__.py +9 -0
- naeural_client/const/base.py +101 -0
- naeural_client/const/comms.py +80 -0
- naeural_client/const/environment.py +26 -0
- naeural_client/const/formatter.py +7 -0
- naeural_client/const/heartbeat.py +111 -0
- naeural_client/const/misc.py +20 -0
- naeural_client/const/payload.py +190 -0
- naeural_client/default/__init__.py +1 -0
- naeural_client/default/instance/__init__.py +4 -0
- naeural_client/default/instance/chain_dist_custom_job_01_plugin.py +54 -0
- naeural_client/default/instance/custom_web_app_01_plugin.py +118 -0
- naeural_client/default/instance/net_mon_01_plugin.py +45 -0
- naeural_client/default/instance/view_scene_01_plugin.py +28 -0
- naeural_client/default/session/mqtt_session.py +72 -0
- naeural_client/io_formatter/__init__.py +2 -0
- naeural_client/io_formatter/base/__init__.py +1 -0
- naeural_client/io_formatter/base/base_formatter.py +80 -0
- naeural_client/io_formatter/default/__init__.py +3 -0
- naeural_client/io_formatter/default/a_dummy.py +51 -0
- naeural_client/io_formatter/default/aixp1.py +113 -0
- naeural_client/io_formatter/default/default.py +22 -0
- naeural_client/io_formatter/io_formatter_manager.py +96 -0
- naeural_client/logging/__init__.py +1 -0
- naeural_client/logging/base_logger.py +2056 -0
- naeural_client/logging/logger_mixins/__init__.py +12 -0
- naeural_client/logging/logger_mixins/class_instance_mixin.py +92 -0
- naeural_client/logging/logger_mixins/computer_vision_mixin.py +443 -0
- naeural_client/logging/logger_mixins/datetime_mixin.py +344 -0
- naeural_client/logging/logger_mixins/download_mixin.py +421 -0
- naeural_client/logging/logger_mixins/general_serialization_mixin.py +242 -0
- naeural_client/logging/logger_mixins/json_serialization_mixin.py +481 -0
- naeural_client/logging/logger_mixins/pickle_serialization_mixin.py +301 -0
- naeural_client/logging/logger_mixins/process_mixin.py +63 -0
- naeural_client/logging/logger_mixins/resource_size_mixin.py +81 -0
- naeural_client/logging/logger_mixins/timers_mixin.py +501 -0
- naeural_client/logging/logger_mixins/upload_mixin.py +260 -0
- naeural_client/logging/logger_mixins/utils_mixin.py +675 -0
- naeural_client/logging/small_logger.py +93 -0
- naeural_client/logging/tzlocal/__init__.py +20 -0
- naeural_client/logging/tzlocal/unix.py +231 -0
- naeural_client/logging/tzlocal/utils.py +113 -0
- naeural_client/logging/tzlocal/win32.py +151 -0
- naeural_client/logging/tzlocal/windows_tz.py +718 -0
- naeural_client/plugins_manager_mixin.py +273 -0
- naeural_client/utils/__init__.py +2 -0
- naeural_client/utils/comm_utils.py +44 -0
- naeural_client/utils/dotenv.py +75 -0
- naeural_client-2.0.0.dist-info/METADATA +365 -0
- naeural_client-2.0.0.dist-info/RECORD +78 -0
- naeural_client-2.0.0.dist-info/WHEEL +4 -0
- naeural_client-2.0.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,260 @@
|
|
1
|
+
import os
|
2
|
+
from time import time
|
3
|
+
from datetime import datetime as dttm
|
4
|
+
from datetime import timedelta as tdelta
|
5
|
+
from uuid import uuid4
|
6
|
+
from datetime import timedelta
|
7
|
+
|
8
|
+
class _UploadMixin(object):
|
9
|
+
"""
|
10
|
+
Mixin for upload functionalities that are attached to `pye2.Logger`.
|
11
|
+
|
12
|
+
This mixin cannot be instantiated because it is built just to provide some additional
|
13
|
+
functionalities for `pye2.Logger`
|
14
|
+
|
15
|
+
In this mixin we can use any attribute/method of the Logger.
|
16
|
+
"""
|
17
|
+
|
18
|
+
def __init__(self):
|
19
|
+
super(_UploadMixin, self).__init__()
|
20
|
+
return
|
21
|
+
|
22
|
+
def minio_upload(self,
|
23
|
+
file_path,
|
24
|
+
endpoint,
|
25
|
+
access_key,
|
26
|
+
secret_key,
|
27
|
+
bucket_name,
|
28
|
+
object_name=None,
|
29
|
+
days_retention=None,
|
30
|
+
debug=False,
|
31
|
+
return_object_name=False,
|
32
|
+
secure=False,
|
33
|
+
SSL_CERT_FILE=None,
|
34
|
+
**kwargs,
|
35
|
+
):
|
36
|
+
"""
|
37
|
+
|
38
|
+
|
39
|
+
Parameters
|
40
|
+
----------
|
41
|
+
file_path : str
|
42
|
+
relative or full path to file.
|
43
|
+
endpoint : str
|
44
|
+
address of the MinIO server.
|
45
|
+
access_key : str
|
46
|
+
user.
|
47
|
+
secret_key : str
|
48
|
+
password.
|
49
|
+
bucket_name : str
|
50
|
+
preconfigureg bucket name.
|
51
|
+
object_name : str, optional
|
52
|
+
a object name - can be None and will be auto-generated. The default is None.
|
53
|
+
days_retention : int, optional
|
54
|
+
how many days before auto-delete. The default is None.
|
55
|
+
debug : bool, optional
|
56
|
+
The default is False.
|
57
|
+
|
58
|
+
|
59
|
+
Returns
|
60
|
+
-------
|
61
|
+
Tuple(URL, Object_name) if return_object_name=True or just URL
|
62
|
+
Returns URL of the downloadable file as well as the object name (or None in case o exception)
|
63
|
+
Object_name can be further used with
|
64
|
+
|
65
|
+
"""
|
66
|
+
from minio import Minio
|
67
|
+
from minio.commonconfig import GOVERNANCE
|
68
|
+
from minio.retention import Retention
|
69
|
+
import urllib3
|
70
|
+
|
71
|
+
if object_name is None:
|
72
|
+
object_name = "OBJ_"+ str(uuid4()).upper().replace('-','')
|
73
|
+
|
74
|
+
# canceled try-except - better catch the exception in upper layers
|
75
|
+
start_up = time()
|
76
|
+
|
77
|
+
http_client = None
|
78
|
+
cert_reqs = None
|
79
|
+
if secure:
|
80
|
+
if SSL_CERT_FILE is not None:
|
81
|
+
if not os.path.isfile(SSL_CERT_FILE):
|
82
|
+
raise ValueError("Invalid SSL_CERT_FILE in config")
|
83
|
+
else:
|
84
|
+
cert_reqs = 'CERT_REQUIRED'
|
85
|
+
else:
|
86
|
+
cert_reqs = 'CERT_NONE'
|
87
|
+
|
88
|
+
|
89
|
+
timeout = timedelta(minutes=5).seconds
|
90
|
+
http_client = urllib3.PoolManager(
|
91
|
+
timeout=urllib3.util.Timeout(connect=timeout, read=timeout),
|
92
|
+
maxsize=10,
|
93
|
+
cert_reqs=cert_reqs,
|
94
|
+
ca_certs=SSL_CERT_FILE,
|
95
|
+
retries=urllib3.Retry(
|
96
|
+
total=5,
|
97
|
+
backoff_factor=0.2,
|
98
|
+
status_forcelist=[500, 502, 503, 504]
|
99
|
+
)
|
100
|
+
)
|
101
|
+
|
102
|
+
self.P("Uploading '{} to minio: <{} {} @ {}> secure:{}, cert_reqs:'{}'...".format(
|
103
|
+
file_path, access_key, secret_key, endpoint, secure, cert_reqs,
|
104
|
+
)
|
105
|
+
)
|
106
|
+
client = Minio(
|
107
|
+
endpoint=endpoint,
|
108
|
+
access_key=access_key,
|
109
|
+
secret_key=secret_key,
|
110
|
+
secure=secure,
|
111
|
+
http_client=http_client,
|
112
|
+
)
|
113
|
+
|
114
|
+
retention = None
|
115
|
+
if days_retention is not None:
|
116
|
+
date = dttm.utcnow().replace(
|
117
|
+
hour=0, minute=0, second=0, microsecond=0,
|
118
|
+
) + tdelta(days=days_retention)
|
119
|
+
retention = Retention(GOVERNANCE, date)
|
120
|
+
|
121
|
+
result = client.fput_object(
|
122
|
+
file_path=file_path,
|
123
|
+
bucket_name=bucket_name,
|
124
|
+
object_name=object_name,
|
125
|
+
retention=retention,
|
126
|
+
)
|
127
|
+
object_name = result.object_name
|
128
|
+
url = client.presigned_get_object(
|
129
|
+
bucket_name=result.bucket_name,
|
130
|
+
object_name=result.object_name,
|
131
|
+
)
|
132
|
+
self.P("Uploaded '{}' as '{}' in {:.2f}s".format(file_path, url, time()-start_up), color='g')
|
133
|
+
|
134
|
+
res = url
|
135
|
+
if return_object_name:
|
136
|
+
res = url, object_name
|
137
|
+
|
138
|
+
return res
|
139
|
+
|
140
|
+
def dropbox_upload(self,
|
141
|
+
access_token,
|
142
|
+
file_path,
|
143
|
+
target_path,
|
144
|
+
timeout=900,
|
145
|
+
chunk_size=4 * 1024 * 1024,
|
146
|
+
url_type='temporary',
|
147
|
+
progress_fn=None,
|
148
|
+
verbose=1,
|
149
|
+
):
|
150
|
+
|
151
|
+
"""
|
152
|
+
Uploads in the folder specific to a dropbox application.
|
153
|
+
|
154
|
+
Steps:
|
155
|
+
1. access https://www.dropbox.com/developers/apps
|
156
|
+
2. create your app
|
157
|
+
3. generate an unlimited access token
|
158
|
+
|
159
|
+
Parameters
|
160
|
+
----------
|
161
|
+
|
162
|
+
access_token : str
|
163
|
+
The token generated in the dropbox app @ step 3
|
164
|
+
|
165
|
+
file_path : str
|
166
|
+
Path to the local file that needs to be uploaded in dropbox
|
167
|
+
|
168
|
+
target_path : str
|
169
|
+
Path to the remote dropbox path. Very important! This should start
|
170
|
+
with '/' (e.g. '/DATA/file.txt')
|
171
|
+
|
172
|
+
timeout : int, optional
|
173
|
+
Parameter that is passed to the dropbox.Dropbox constructor
|
174
|
+
The default is 900.
|
175
|
+
|
176
|
+
chunk_size : int, optional
|
177
|
+
Specifies how many bytes are uploaded progressively. If it's None,
|
178
|
+
then the whole file is uploaded one time. Very important! If the
|
179
|
+
file is big enough and `chunk_size=None` then errors may occur.
|
180
|
+
The default is 4*1024*1024
|
181
|
+
|
182
|
+
url_type : str
|
183
|
+
Type of url to be generated after the file is uploaded: temporary or shared
|
184
|
+
|
185
|
+
progress_fn: callback
|
186
|
+
Will be used to report the current progress percent
|
187
|
+
|
188
|
+
verbose: int, optional
|
189
|
+
Verbosity level
|
190
|
+
Default value 1
|
191
|
+
|
192
|
+
Returns
|
193
|
+
-------
|
194
|
+
A downloadable link of the uploaded file
|
195
|
+
|
196
|
+
"""
|
197
|
+
|
198
|
+
#TODO make it thread safe - remove tqdm and print only when the main thread calls the method
|
199
|
+
|
200
|
+
def _progress(crt, total):
|
201
|
+
return min(100.0, 100.0 * crt / total)
|
202
|
+
|
203
|
+
assert url_type in ['temporary', 'shared']
|
204
|
+
|
205
|
+
import dropbox
|
206
|
+
|
207
|
+
uploaded_size = 0
|
208
|
+
dbx = dropbox.Dropbox(access_token, timeout=timeout)
|
209
|
+
|
210
|
+
if chunk_size is None:
|
211
|
+
with open(file_path, 'rb') as f:
|
212
|
+
dbx.files_upload(f.read(), target_path)
|
213
|
+
else:
|
214
|
+
with open(file_path, "rb") as f:
|
215
|
+
file_size = os.path.getsize(file_path)
|
216
|
+
if file_size <= chunk_size:
|
217
|
+
dbx.files_upload(f.read(), target_path)
|
218
|
+
else:
|
219
|
+
upload_session_start_result = dbx.files_upload_session_start(
|
220
|
+
f.read(chunk_size)
|
221
|
+
)
|
222
|
+
uploaded_size += chunk_size
|
223
|
+
cursor = dropbox.files.UploadSessionCursor(
|
224
|
+
session_id=upload_session_start_result.session_id,
|
225
|
+
offset=f.tell(),
|
226
|
+
)
|
227
|
+
commit = dropbox.files.CommitInfo(path=target_path)
|
228
|
+
while f.tell() < file_size:
|
229
|
+
if (file_size - f.tell()) <= chunk_size:
|
230
|
+
dbx.files_upload_session_finish(
|
231
|
+
f.read(chunk_size), cursor, commit
|
232
|
+
)
|
233
|
+
else:
|
234
|
+
dbx.files_upload_session_append(
|
235
|
+
f.read(chunk_size),
|
236
|
+
cursor.session_id,
|
237
|
+
cursor.offset,
|
238
|
+
)
|
239
|
+
cursor.offset = f.tell()
|
240
|
+
# endif
|
241
|
+
# pbar.update(chunk_size)
|
242
|
+
uploaded_size += chunk_size
|
243
|
+
progress_prc = _progress(uploaded_size, file_size)
|
244
|
+
if verbose >= 1 and self.is_main_thread:
|
245
|
+
print('\r[...{}] Uploaded {:.2f}%'.format(file_path[-50:], progress_prc), flush=True, end='')
|
246
|
+
|
247
|
+
if progress_fn:
|
248
|
+
progress_fn(progress_prc)
|
249
|
+
# end while
|
250
|
+
# endif
|
251
|
+
# endwith
|
252
|
+
# endif
|
253
|
+
|
254
|
+
url = None
|
255
|
+
if url_type == 'temporary':
|
256
|
+
url = dbx.files_get_temporary_link(target_path).link
|
257
|
+
else:
|
258
|
+
url = dbx.sharing_create_shared_link(target_path).url
|
259
|
+
return url
|
260
|
+
# enddef
|