From 60f9290d02dec523ba24bc2d2004c5e428892e8d Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Wed, 23 Jan 2019 15:35:27 +0100 Subject: [PATCH] Fix ZeroDivisionException in meter.PBTextMeter If size is 0, using pb.Percentage will result in a ZeroDivisionException. Note: the output in case of size == 0 looks a bit "strange" - for a consistent output we should probably subclass pb.Percentage. --- osc/meter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osc/meter.py b/osc/meter.py index f699aa14..3372a1a1 100644 --- a/osc/meter.py +++ b/osc/meter.py @@ -17,8 +17,11 @@ class PBTextMeter(object): widgets = [basename + ': ', pb.AnimatedMarker(), ' ', pb.Timer()] self.bar = pb.ProgressBar(widgets=widgets, maxval=pb.UnknownLength) else: - widgets = [basename + ': ', pb.Percentage(), pb.Bar(), ' ', - pb.ETA()] + widgets = [basename + ': ', pb.Bar(), ' ', pb.ETA()] + if size: + # if size is 0, using pb.Percentage will result in + # a ZeroDivisionException + widgets.insert(1, pb.Percentage()) self.bar = pb.ProgressBar(widgets=widgets, maxval=size) self.bar.start()