1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-29 03:06:15 +01:00
github.com_openSUSE_osc/osc/meter.py
lethliel 8b3c2bd61a improve handling of missing progressbar module
With the NoPBTextMeter class the build view gets broken.
Old view:
1/11 (repo) filename

new view:
Please install the progressbar module...
Please install the progressbar module...
Please install the progressbar module...

With this commit the old behavior is restored.

The getbinaries call now lists the file he downloads instead of just
stating "Please install the progressbar module..." several times.
(but only if not called with the option quiet)
2019-01-11 10:16:02 +01:00

37 lines
1.0 KiB
Python

# Copyright (C) 2018 SUSE Linux. All rights reserved.
# This program is free software; it may be used, copied, modified
# and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version.
try:
import progressbar as pb
have_pb_module = True
except ImportError:
have_pb_module = False
class PBTextMeter(object):
def start(self, basename, size=None):
if size is None:
widgets = [basename + ': ', pb.AnimatedMarker(), ' ', pb.Timer()]
self.bar = pb.ProgressBar(widgets=widgets, maxval=pb.UnknownLength)
else:
widgets = [basename + ': ', pb.Percentage(), pb.Bar(), ' ',
pb.ETA()]
self.bar = pb.ProgressBar(widgets=widgets, maxval=size)
self.bar.start()
def update(self, amount_read):
self.bar.update(amount_read)
def end(self):
self.bar.finish()
if have_pb_module:
TextMeter = PBTextMeter
else:
TextMeter = None
# vim: sw=4 et