mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-29 03:06:15 +01:00
93d15fc83b
* new function create_text_meter with fallback selection * NoPBTextMeter.start() will print the basename (if not stated otherise with basename = None) * The callers that should use an alternare TextMeter class now call create_text_meter() * The callers that should not use and alternate TextMeter (because of different handling, like build.py) call create_text_meter(use_pb_fallback=False) * the warning 'Please install the progressbar module' is now only shown once improvements
59 lines
1.6 KiB
Python
59 lines
1.6 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()
|
|
|
|
|
|
class NoPBTextMeter(object):
|
|
_complained = False
|
|
|
|
def start(self, basename, size=None):
|
|
if not self._complained:
|
|
print('Please install the progressbar module')
|
|
NoPBTextMeter._complained = True
|
|
print('Processing: %s' % basename)
|
|
|
|
def update(self, *args, **kwargs):
|
|
pass
|
|
|
|
def end(self, *args, **kwargs):
|
|
pass
|
|
|
|
|
|
def create_text_meter(*args, **kwargs):
|
|
use_pb_fallback = kwargs.pop('use_pb_fallback', True)
|
|
if have_pb_module or use_pb_fallback:
|
|
return TextMeter(*args, **kwargs)
|
|
return None
|
|
|
|
if have_pb_module:
|
|
TextMeter = PBTextMeter
|
|
else:
|
|
TextMeter = NoPBTextMeter
|
|
# vim: sw=4 et
|