NGPIris 5.3.0__tar.gz → 5.3.1__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.
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hcp/hcp.py +68 -22
- {ngpiris-5.3.0 → ngpiris-5.3.1/NGPIris.egg-info}/PKG-INFO +1 -1
- {ngpiris-5.3.0/NGPIris.egg-info → ngpiris-5.3.1}/PKG-INFO +1 -1
- {ngpiris-5.3.0 → ngpiris-5.3.1}/pyproject.toml +1 -1
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/test_hcp.py +36 -12
- {ngpiris-5.3.0 → ngpiris-5.3.1}/LICENSE +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/MANIFEST.in +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/__init__.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/cli/__init__.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hci/__init__.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hci/exceptions.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hci/hci.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hci/helpers.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hcp/__init__.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hcp/exceptions.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hcp/helpers.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/hcp/statistics.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/parse_credentials/__init__.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/parse_credentials/parse_credentials.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/utils/__init__.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris/utils/utils.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris.egg-info/SOURCES.txt +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris.egg-info/dependency_links.txt +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris.egg-info/entry_points.txt +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris.egg-info/requires.txt +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/NGPIris.egg-info/top_level.txt +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/README.md +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/IRIS_5_changelog.md +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/Makefile +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/NGPIris.cli.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/NGPIris.hci.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/NGPIris.hcp.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/NGPIris.parse_credentials.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/NGPIris.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/NGPIris.utils.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/Tutorial.md +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/conf.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/index.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/make.bat +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/docs/modules.rst +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/setup.cfg +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/80MB_test_file +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/a folder of data/80MB_test_file_0 +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/a folder of data/80MB_test_file_1 +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/complete_creds_0.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/complete_creds_1.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/complete_creds_2.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/incomplete_creds_0.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/incomplete_creds_1.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/incomplete_creds_2.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/incomplete_creds_3.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/data/incomplete_creds_4.json +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/test_hci.py +0 -0
- {ngpiris-5.3.0 → ngpiris-5.3.1}/tests/test_parse_credentials.py +0 -0
|
@@ -340,7 +340,7 @@ class HCPHandler:
|
|
|
340
340
|
return False
|
|
341
341
|
|
|
342
342
|
@check_mounted
|
|
343
|
-
def download_file(self, key : str, local_file_path : str) -> None:
|
|
343
|
+
def download_file(self, key : str, local_file_path : str, show_progress_bar : bool = True) -> None:
|
|
344
344
|
"""
|
|
345
345
|
Download one object file from the mounted bucket
|
|
346
346
|
|
|
@@ -349,25 +349,38 @@ class HCPHandler:
|
|
|
349
349
|
|
|
350
350
|
:param local_file_path: Path to a file on your local system where the contents of the object file can be put
|
|
351
351
|
:type local_file_path: str
|
|
352
|
+
|
|
353
|
+
:param show_progress_bar: Boolean choice of displaying a progress bar. Defaults to True
|
|
354
|
+
:type show_progress_bar: bool, optional
|
|
355
|
+
|
|
356
|
+
:raises ObjectDoesNotExist: If the object does not exist in the bucket
|
|
352
357
|
"""
|
|
353
358
|
try:
|
|
354
359
|
self.get_object(key)
|
|
355
360
|
except:
|
|
356
361
|
raise ObjectDoesNotExist("Could not find object", "\"" + key + "\"", "in bucket", "\"" + str(self.bucket_name) + "\"")
|
|
357
362
|
try:
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
363
|
+
if show_progress_bar:
|
|
364
|
+
file_size : int = self.s3_client.head_object(Bucket = self.bucket_name, Key = key)["ContentLength"]
|
|
365
|
+
with tqdm(
|
|
366
|
+
total = file_size,
|
|
367
|
+
unit = "B",
|
|
368
|
+
unit_scale = True,
|
|
369
|
+
desc = key
|
|
370
|
+
) as pbar:
|
|
371
|
+
self.s3_client.download_file(
|
|
372
|
+
Bucket = self.bucket_name,
|
|
373
|
+
Key = key,
|
|
374
|
+
Filename = local_file_path,
|
|
375
|
+
Config = self.transfer_config,
|
|
376
|
+
Callback = lambda bytes_transferred : pbar.update(bytes_transferred)
|
|
377
|
+
)
|
|
378
|
+
else:
|
|
365
379
|
self.s3_client.download_file(
|
|
366
380
|
Bucket = self.bucket_name,
|
|
367
381
|
Key = key,
|
|
368
382
|
Filename = local_file_path,
|
|
369
383
|
Config = self.transfer_config,
|
|
370
|
-
Callback = lambda bytes_transferred : pbar.update(bytes_transferred)
|
|
371
384
|
)
|
|
372
385
|
except ClientError as e0:
|
|
373
386
|
print(str(e0))
|
|
@@ -376,7 +389,14 @@ class HCPHandler:
|
|
|
376
389
|
raise Exception(e)
|
|
377
390
|
|
|
378
391
|
@check_mounted
|
|
379
|
-
def download_folder(
|
|
392
|
+
def download_folder(
|
|
393
|
+
self,
|
|
394
|
+
folder_key : str,
|
|
395
|
+
local_folder_path : str,
|
|
396
|
+
use_download_limit : bool = False,
|
|
397
|
+
download_limit_in_bytes : Byte = TiB(1).to_Byte(),
|
|
398
|
+
show_progress_bar : bool = True
|
|
399
|
+
) -> None:
|
|
380
400
|
"""
|
|
381
401
|
Download multiple objects from a folder in the mounted bucket
|
|
382
402
|
|
|
@@ -392,7 +412,13 @@ class HCPHandler:
|
|
|
392
412
|
:param download_limit_in_bytes: The optional download limit in Byte (from the package `bitmath`). Defaults to 1 TB (`TiB(1).to_Byte()`)
|
|
393
413
|
:type download_limit_in_bytes: Byte, optional
|
|
394
414
|
|
|
415
|
+
:param show_progress_bar: Boolean choice of displaying a progress bar. Defaults to True
|
|
416
|
+
:type show_progress_bar: bool, optional
|
|
417
|
+
|
|
418
|
+
:raises ObjectDoesNotExist: If the object does not exist in the bucket
|
|
419
|
+
|
|
395
420
|
:raises DownloadLimitReached: If download limit was reached while downloading files
|
|
421
|
+
|
|
396
422
|
:raises NotADirectory: If local_folder_path is not a directory
|
|
397
423
|
"""
|
|
398
424
|
try:
|
|
@@ -409,12 +435,12 @@ class HCPHandler:
|
|
|
409
435
|
current_download_size_in_bytes += Byte(object["Size"])
|
|
410
436
|
if current_download_size_in_bytes >= download_limit_in_bytes and use_download_limit:
|
|
411
437
|
raise DownloadLimitReached("The download limit was reached when downloading files")
|
|
412
|
-
self.download_file(object["Key"], p.as_posix())
|
|
438
|
+
self.download_file(object["Key"], p.as_posix(), show_progress_bar = show_progress_bar)
|
|
413
439
|
else:
|
|
414
440
|
raise NotADirectory(local_folder_path + " is not a directory")
|
|
415
441
|
|
|
416
442
|
@check_mounted
|
|
417
|
-
def upload_file(self, local_file_path : str, key : str = "") -> None:
|
|
443
|
+
def upload_file(self, local_file_path : str, key : str = "", show_progress_bar : bool = True) -> None:
|
|
418
444
|
"""
|
|
419
445
|
Upload one file to the mounted bucket
|
|
420
446
|
|
|
@@ -423,6 +449,13 @@ class HCPHandler:
|
|
|
423
449
|
|
|
424
450
|
:param key: An optional new name for the file object on the bucket. Defaults to the same name as the file
|
|
425
451
|
:type key: str, optional
|
|
452
|
+
|
|
453
|
+
:param show_progress_bar: Boolean choice of displaying a progress bar. Defaults to True
|
|
454
|
+
:type show_progress_bar: bool, optional
|
|
455
|
+
|
|
456
|
+
:raises RuntimeError: If the \"\\\" is used in the file path
|
|
457
|
+
|
|
458
|
+
:raises ObjectAlreadyExist: If the object already exist on the mounted bucket
|
|
426
459
|
"""
|
|
427
460
|
raise_path_error(local_file_path)
|
|
428
461
|
|
|
@@ -436,30 +469,43 @@ class HCPHandler:
|
|
|
436
469
|
if self.object_exists(key):
|
|
437
470
|
raise ObjectAlreadyExist("The object \"" + key + "\" already exist in the mounted bucket")
|
|
438
471
|
else:
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
472
|
+
if show_progress_bar:
|
|
473
|
+
file_size : int = stat(local_file_path).st_size
|
|
474
|
+
with tqdm(
|
|
475
|
+
total = file_size,
|
|
476
|
+
unit = "B",
|
|
477
|
+
unit_scale = True,
|
|
478
|
+
desc = local_file_path
|
|
479
|
+
) as pbar:
|
|
480
|
+
self.s3_client.upload_file(
|
|
481
|
+
Filename = local_file_path,
|
|
482
|
+
Bucket = self.bucket_name,
|
|
483
|
+
Key = key,
|
|
484
|
+
Config = self.transfer_config,
|
|
485
|
+
Callback = lambda bytes_transferred : pbar.update(bytes_transferred)
|
|
486
|
+
)
|
|
487
|
+
else:
|
|
446
488
|
self.s3_client.upload_file(
|
|
447
489
|
Filename = local_file_path,
|
|
448
490
|
Bucket = self.bucket_name,
|
|
449
491
|
Key = key,
|
|
450
492
|
Config = self.transfer_config,
|
|
451
|
-
Callback = lambda bytes_transferred : pbar.update(bytes_transferred)
|
|
452
493
|
)
|
|
453
494
|
|
|
495
|
+
|
|
454
496
|
@check_mounted
|
|
455
|
-
def upload_folder(self, local_folder_path : str, key : str = "") -> None:
|
|
497
|
+
def upload_folder(self, local_folder_path : str, key : str = "", show_progress_bar : bool = True) -> None:
|
|
456
498
|
"""
|
|
457
499
|
Upload the contents of a folder to the mounted bucket
|
|
458
500
|
|
|
459
501
|
:param local_folder_path: Path to the folder to be uploaded
|
|
460
502
|
:type local_folder_path: str
|
|
503
|
+
|
|
461
504
|
:param key: An optional new name for the folder path on the bucket. Defaults to the same name as the local folder path
|
|
462
505
|
:type key: str, optional
|
|
506
|
+
|
|
507
|
+
:param show_progress_bar: Boolean choice of displaying a progress bar. Defaults to True
|
|
508
|
+
:type show_progress_bar: bool, optional
|
|
463
509
|
"""
|
|
464
510
|
raise_path_error(local_folder_path)
|
|
465
511
|
|
|
@@ -468,7 +514,7 @@ class HCPHandler:
|
|
|
468
514
|
filenames = listdir(local_folder_path)
|
|
469
515
|
|
|
470
516
|
for filename in filenames:
|
|
471
|
-
self.upload_file(local_folder_path + filename, key + filename)
|
|
517
|
+
self.upload_file(local_folder_path + filename, key + filename, show_progress_bar = show_progress_bar)
|
|
472
518
|
|
|
473
519
|
@check_mounted
|
|
474
520
|
def delete_objects(self, keys : list[str], verbose : bool = True) -> None:
|
|
@@ -56,7 +56,19 @@ def test_list_objects_without_mounting(custom_config : CustomConfig) -> None:
|
|
|
56
56
|
|
|
57
57
|
def test_upload_file(custom_config : CustomConfig) -> None:
|
|
58
58
|
test_mount_bucket(custom_config)
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
# With progress bar
|
|
61
|
+
custom_config.hcp_h.upload_file(
|
|
62
|
+
custom_config.test_file_path,
|
|
63
|
+
custom_config.test_file_path
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Without progress bar
|
|
67
|
+
custom_config.hcp_h.upload_file(
|
|
68
|
+
custom_config.test_file_path,
|
|
69
|
+
custom_config.test_file_path + "_no_progress_bar",
|
|
70
|
+
show_progress_bar = False
|
|
71
|
+
)
|
|
60
72
|
|
|
61
73
|
def test_upload_file_without_mounting(custom_config : CustomConfig) -> None:
|
|
62
74
|
_hcp_h = custom_config.hcp_h
|
|
@@ -104,16 +116,29 @@ def test_get_folder_without_mounting(custom_config : CustomConfig) -> None:
|
|
|
104
116
|
|
|
105
117
|
def test_get_file_in_sub_directory(custom_config : CustomConfig) -> None:
|
|
106
118
|
test_mount_bucket(custom_config)
|
|
107
|
-
|
|
108
|
-
assert custom_config.hcp_h.
|
|
109
|
-
|
|
119
|
+
assert custom_config.hcp_h.object_exists(custom_config.test_file_path)
|
|
120
|
+
assert custom_config.hcp_h.get_object(custom_config.test_file_path)
|
|
121
|
+
|
|
122
|
+
from icecream import ic
|
|
110
123
|
|
|
111
124
|
def test_download_file(custom_config : CustomConfig) -> None:
|
|
112
125
|
test_mount_bucket(custom_config)
|
|
113
|
-
Path(custom_config.result_path).mkdir()
|
|
114
|
-
|
|
115
|
-
custom_config.
|
|
116
|
-
|
|
126
|
+
Path(custom_config.result_path).mkdir()
|
|
127
|
+
|
|
128
|
+
test_folder_path = str(custom_config.test_file_path).rsplit("/", maxsplit = 1)[0] + "/"
|
|
129
|
+
Path(custom_config.result_path + test_folder_path).mkdir(parents = True, exist_ok = True)
|
|
130
|
+
|
|
131
|
+
# With progress bar
|
|
132
|
+
custom_config.hcp_h.download_file(custom_config.test_file_path, custom_config.result_path + custom_config.test_file_path)
|
|
133
|
+
assert cmp(custom_config.result_path + custom_config.test_file_path, custom_config.test_file_path)
|
|
134
|
+
|
|
135
|
+
# Without progress bar
|
|
136
|
+
custom_config.hcp_h.download_file(
|
|
137
|
+
custom_config.test_file_path + "_no_progress_bar",
|
|
138
|
+
custom_config.result_path + custom_config.test_file_path + "_no_progress_bar",
|
|
139
|
+
show_progress_bar = False
|
|
140
|
+
)
|
|
141
|
+
assert cmp(custom_config.result_path + custom_config.test_file_path, custom_config.test_file_path)
|
|
117
142
|
|
|
118
143
|
def test_download_file_without_mounting(custom_config : CustomConfig) -> None:
|
|
119
144
|
_hcp_h = custom_config.hcp_h
|
|
@@ -152,8 +177,7 @@ def test_fuzzy_search_in_bucket_without_mounting(custom_config : CustomConfig) -
|
|
|
152
177
|
|
|
153
178
|
def test_get_object_acl(custom_config : CustomConfig) -> None:
|
|
154
179
|
test_mount_bucket(custom_config)
|
|
155
|
-
|
|
156
|
-
custom_config.hcp_h.get_object_acl(test_file)
|
|
180
|
+
custom_config.hcp_h.get_object_acl(custom_config.test_file_path)
|
|
157
181
|
|
|
158
182
|
def test_get_object_acl_without_mounting(custom_config : CustomConfig) -> None:
|
|
159
183
|
_hcp_h = custom_config.hcp_h
|
|
@@ -189,8 +213,8 @@ def test_get_bucket_acl_without_mounting(custom_config : CustomConfig) -> None:
|
|
|
189
213
|
|
|
190
214
|
def test_delete_file(custom_config : CustomConfig) -> None:
|
|
191
215
|
test_mount_bucket(custom_config)
|
|
192
|
-
|
|
193
|
-
custom_config.hcp_h.delete_object(
|
|
216
|
+
custom_config.hcp_h.delete_object(custom_config.test_file_path)
|
|
217
|
+
custom_config.hcp_h.delete_object(custom_config.test_file_path + "_no_progress_bar")
|
|
194
218
|
custom_config.hcp_h.delete_object("a_sub_directory/a_file")
|
|
195
219
|
custom_config.hcp_h.delete_object("a_sub_directory")
|
|
196
220
|
|
|
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
|
|
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
|
|
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
|
|
File without changes
|