pybiolib 1.1.1558__py3-none-any.whl → 1.1.1564__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.
- biolib/biolib_binary_format/file_in_container.py +57 -31
- {pybiolib-1.1.1558.dist-info → pybiolib-1.1.1564.dist-info}/METADATA +1 -1
- {pybiolib-1.1.1558.dist-info → pybiolib-1.1.1564.dist-info}/RECORD +6 -6
- {pybiolib-1.1.1558.dist-info → pybiolib-1.1.1564.dist-info}/LICENSE +0 -0
- {pybiolib-1.1.1558.dist-info → pybiolib-1.1.1564.dist-info}/WHEEL +0 -0
- {pybiolib-1.1.1558.dist-info → pybiolib-1.1.1564.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
import io
|
2
1
|
import os.path
|
3
2
|
import tarfile
|
3
|
+
import tempfile
|
4
4
|
|
5
5
|
from docker.models.containers import Container # type: ignore
|
6
6
|
|
@@ -32,48 +32,74 @@ class FileInContainer:
|
|
32
32
|
if self._path_on_disk:
|
33
33
|
return os.path.isfile(self._path_on_disk)
|
34
34
|
else:
|
35
|
-
|
35
|
+
tmp_file = self._get_temp_file_from_container_via_tar()
|
36
|
+
if tmp_file:
|
37
|
+
os.remove(tmp_file)
|
38
|
+
return True
|
39
|
+
else:
|
40
|
+
return False
|
36
41
|
|
37
42
|
def get_data_size_in_bytes(self) -> int:
|
38
43
|
if self._path_on_disk:
|
39
44
|
return os.path.getsize(self._path_on_disk)
|
40
45
|
else:
|
41
|
-
|
42
|
-
|
46
|
+
tmp_file = self._get_temp_file_from_container_via_tar()
|
47
|
+
if tmp_file:
|
48
|
+
file_length = os.path.getsize(tmp_file)
|
49
|
+
os.remove(tmp_file)
|
50
|
+
return file_length
|
51
|
+
else:
|
52
|
+
return 0
|
43
53
|
|
44
54
|
def get_data_stream(self) -> Iterable[bytes]:
|
45
55
|
if self._path_on_disk:
|
46
56
|
with open(self._path_on_disk, mode='rb') as file:
|
47
57
|
while True:
|
48
|
-
chunk = file.read(
|
58
|
+
chunk = file.read(1_000_000)
|
49
59
|
if not chunk:
|
50
60
|
return
|
51
61
|
|
52
62
|
yield chunk
|
53
63
|
else:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
64
|
+
tmp_file = self._get_temp_file_from_container_via_tar()
|
65
|
+
if not tmp_file:
|
66
|
+
yield bytes()
|
67
|
+
return
|
68
|
+
else:
|
69
|
+
file = open(tmp_file, mode='rb')
|
70
|
+
while True:
|
71
|
+
chunk = file.read(1_000_000)
|
72
|
+
if not chunk:
|
73
|
+
file.close()
|
74
|
+
os.remove(tmp_file)
|
75
|
+
return
|
76
|
+
|
77
|
+
yield chunk
|
78
|
+
|
79
|
+
def _get_temp_file_from_container_via_tar(self) -> Optional[str]:
|
80
|
+
with tempfile.NamedTemporaryFile(mode='w+', delete=True) as tmp_io:
|
81
|
+
stream, _ = self._container.get_archive(path=self._path_in_container)
|
82
|
+
for chunk in stream:
|
83
|
+
tmp_io.write(chunk)
|
84
|
+
|
85
|
+
tmp_io.seek(0)
|
86
|
+
with tarfile.open(tmp_io.name) as tar:
|
87
|
+
members = tar.getmembers()
|
88
|
+
file_members = [member for member in members if member.isfile()]
|
89
|
+
if not file_members:
|
90
|
+
# Path was not a file
|
91
|
+
return None
|
92
|
+
|
93
|
+
assert len(file_members) == 1
|
94
|
+
file_obj = tar.extractfile(member=file_members[0])
|
95
|
+
if not file_obj:
|
96
|
+
# Path was not a file
|
97
|
+
return None
|
98
|
+
tmp_io_2 = tempfile.NamedTemporaryFile(mode='w+', delete=False)
|
99
|
+
while True:
|
100
|
+
chunk = file_obj.read(1_000_000)
|
101
|
+
if not chunk:
|
102
|
+
break
|
103
|
+
tmp_io_2.write(chunk)
|
104
|
+
tmp_io_2.close()
|
105
|
+
return tmp_io_2.name
|
@@ -21,7 +21,7 @@ biolib/biolib_api_client/lfs_types.py,sha256=xaGjE-yUyNVM3LyKdslJn5ZXWp6_kVCd4o-
|
|
21
21
|
biolib/biolib_api_client/user_state.py,sha256=XcgWV-MgVk88mIlMmnu8yHxMu8OCaw8o0tk7TVo5Hcg,637
|
22
22
|
biolib/biolib_binary_format/__init__.py,sha256=HMl5SdX_VUWE4OQzi4Jf_yFvC7b0bSPOGPHYi9dWM2Q,185
|
23
23
|
biolib/biolib_binary_format/base_bbf_package.py,sha256=vxRV4iKy0dXeDOlFWnMFI0hGnDBYDH5Cgh5gAfuObt8,959
|
24
|
-
biolib/biolib_binary_format/file_in_container.py,sha256=
|
24
|
+
biolib/biolib_binary_format/file_in_container.py,sha256=oAXva2pVEwHs175zjnPAibqTCSkseD6ZVxmOwh8pq48,3591
|
25
25
|
biolib/biolib_binary_format/module_input.py,sha256=led2QhHeec_ymBPw5uEn3_3vJKI-1T8zrFQGqwEWLMY,2788
|
26
26
|
biolib/biolib_binary_format/module_output_v2.py,sha256=J5ZO5gCSeudpE12EVDrjYrNTS2DwgszY-SVXT7Qjuyg,5913
|
27
27
|
biolib/biolib_binary_format/remote_endpoints.py,sha256=LgWd_cewZK4ncPR8303GM_PmIEZZJ5RQatJ_NSXUgbU,1306
|
@@ -99,8 +99,8 @@ biolib/utils/cache_state.py,sha256=BFrZlV4XZIueIFzAFiPidX4hmwADKY5Y5ZuqlerF5l0,3
|
|
99
99
|
biolib/utils/multipart_uploader.py,sha256=PEorMsTNg5f72e3Y-KA3LrI-F6EAnsD9vENV-5EuiX0,9896
|
100
100
|
biolib/utils/seq_util.py,sha256=g4PIw9ovxjO0eg85uBSDRzzvxPkxu9pOT5sEryGD4JA,3105
|
101
101
|
biolib/utils/zip/remote_zip.py,sha256=NCdUnVbGCv7SfXCI-yVU-is_OnyWmLAnVpIdSvo-W4k,23500
|
102
|
-
pybiolib-1.1.
|
103
|
-
pybiolib-1.1.
|
104
|
-
pybiolib-1.1.
|
105
|
-
pybiolib-1.1.
|
106
|
-
pybiolib-1.1.
|
102
|
+
pybiolib-1.1.1564.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
|
103
|
+
pybiolib-1.1.1564.dist-info/METADATA,sha256=HnHMpug5D5I6xVtQrZT71yShKima3sLI1ZWGHMI9yBE,1543
|
104
|
+
pybiolib-1.1.1564.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
105
|
+
pybiolib-1.1.1564.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
|
106
|
+
pybiolib-1.1.1564.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|