Skip to content

Commit 35ceefe

Browse files
author
Hongbin Lu
committed
Return Image objects on image.load
In before, image.load returns what Docker API returns, which is a text stream. This commits propose an improvement for returning more useful information, which is a list of Image objects being loaded. Signed-off-by: Hongbin Lu <[email protected]>
1 parent 37fbc8b commit 35ceefe

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

docker/models/images.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,24 @@ def load(self, data):
236236
data (binary): Image data to be loaded.
237237
238238
Returns:
239-
(generator): Progress output as JSON objects
239+
(list of :py:class:`Image`): The images.
240240
241241
Raises:
242242
:py:class:`docker.errors.APIError`
243243
If the server returns an error.
244244
"""
245-
return self.client.api.load_image(data)
245+
resp = self.client.api.load_image(data)
246+
images = []
247+
for chunk in resp:
248+
if 'stream' in chunk:
249+
match = re.search(
250+
r'(^Loaded image ID: |^Loaded image: )(.+)$',
251+
chunk['stream']
252+
)
253+
if match:
254+
image_id = match.group(2)
255+
images.append(image_id)
256+
return [self.get(i) for i in images]
246257

247258
def pull(self, name, tag=None, **kwargs):
248259
"""

0 commit comments

Comments
 (0)