mirror of https://github.com/docker/compose.git
Merge pull request #1464 from twhiteman/bug1461
Possible division by zero error when pulling an image - fixes #1463
This commit is contained in:
commit
d0e87929a1
|
@ -74,8 +74,9 @@ def print_output_event(event, stream, is_terminal):
|
||||||
stream.write("%s %s%s" % (status, event['progress'], terminator))
|
stream.write("%s %s%s" % (status, event['progress'], terminator))
|
||||||
elif 'progressDetail' in event:
|
elif 'progressDetail' in event:
|
||||||
detail = event['progressDetail']
|
detail = event['progressDetail']
|
||||||
if 'current' in detail:
|
total = detail.get('total')
|
||||||
percentage = float(detail['current']) / float(detail['total']) * 100
|
if 'current' in detail and total:
|
||||||
|
percentage = float(detail['current']) / float(total) * 100
|
||||||
stream.write('%s (%.1f%%)%s' % (status, percentage, terminator))
|
stream.write('%s (%.1f%%)%s' % (status, percentage, terminator))
|
||||||
else:
|
else:
|
||||||
stream.write('%s%s' % (status, terminator))
|
stream.write('%s%s' % (status, terminator))
|
||||||
|
|
|
@ -17,3 +17,21 @@ class ProgressStreamTestCase(unittest.TestCase):
|
||||||
]
|
]
|
||||||
events = progress_stream.stream_output(output, StringIO())
|
events = progress_stream.stream_output(output, StringIO())
|
||||||
self.assertEqual(len(events), 1)
|
self.assertEqual(len(events), 1)
|
||||||
|
|
||||||
|
def test_stream_output_div_zero(self):
|
||||||
|
output = [
|
||||||
|
'{"status": "Downloading", "progressDetail": {"current": '
|
||||||
|
'0, "start": 1413653874, "total": 0}, '
|
||||||
|
'"progress": "..."}',
|
||||||
|
]
|
||||||
|
events = progress_stream.stream_output(output, StringIO())
|
||||||
|
self.assertEqual(len(events), 1)
|
||||||
|
|
||||||
|
def test_stream_output_null_total(self):
|
||||||
|
output = [
|
||||||
|
'{"status": "Downloading", "progressDetail": {"current": '
|
||||||
|
'0, "start": 1413653874, "total": null}, '
|
||||||
|
'"progress": "..."}',
|
||||||
|
]
|
||||||
|
events = progress_stream.stream_output(output, StringIO())
|
||||||
|
self.assertEqual(len(events), 1)
|
||||||
|
|
Loading…
Reference in New Issue