diff --git a/osc/build.py b/osc/build.py index 7beef568..b26ae9c9 100644 --- a/osc/build.py +++ b/osc/build.py @@ -33,7 +33,7 @@ except ImportError: from .conf import config, cookiejar -from .meter import TextMeter +from .meter import create_text_meter change_personality = { 'i686': 'linux32', @@ -305,10 +305,9 @@ def get_preinstall_image(apiurl, arch, cache_dir, img_info): print('packagecachedir is not writable for you?', file=sys.stderr) print(e, file=sys.stderr) sys.exit(1) - if sys.stdout.isatty() and TextMeter: - progress_obj = TextMeter() - else: - progress_obj = None + progress_obj = None + if sys.stdout.isatty(): + progress_obj = create_text_meter(use_pb_fallback=False) gr = OscFileGrabber(progress_obj=progress_obj) try: gr.urlgrab(url, filename=ifile_path_part, text='fetching image') diff --git a/osc/commandline.py b/osc/commandline.py index 8e818a58..c43aa623 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -166,9 +166,8 @@ class Osc(cmdln.Cmdln): self.options.verbose = conf.config['verbose'] self.download_progress = None if conf.config.get('show_download_progress', False): - from .meter import TextMeter - if TextMeter: - self.download_progress = TextMeter() + from .meter import create_text_meter + self.download_progress = create_text_meter() def get_cmd_help(self, cmdname): diff --git a/osc/core.py b/osc/core.py index acd42453..d4f2309a 100644 --- a/osc/core.py +++ b/osc/core.py @@ -4617,15 +4617,11 @@ def get_binary_file(apiurl, prj, repo, arch, progress_meter = False): progress_obj = None if progress_meter: - from .meter import TextMeter - if TextMeter: - progress_obj = TextMeter() + from .meter import create_text_meter + progress_obj = create_text_meter() target_filename = target_filename or filename - if progress_meter and not progress_obj: - print('Downloading %s' % target_filename) - where = package or '_repository' u = makeurl(apiurl, ['build', prj, repo, arch, where, filename]) download(u, target_filename, progress_obj, target_mtime) diff --git a/osc/fetch.py b/osc/fetch.py index aa3189b6..833c8fa5 100644 --- a/osc/fetch.py +++ b/osc/fetch.py @@ -23,19 +23,15 @@ from . import oscerr import tempfile import re -from .meter import TextMeter - -if not TextMeter: - print('Please install the progressbar module') +from .meter import create_text_meter class Fetcher: def __init__(self, cachedir='/tmp', api_host_options={}, urllist=[], http_debug=False, cookiejar=None, offline=False, enable_cpio=True): # set up progress bar callback - if sys.stdout.isatty() and TextMeter: - self.progress_obj = TextMeter() - else: - self.progress_obj = None + self.progress_obj = None + if sys.stdout.isatty(): + self.progress_obj = create_text_meter(use_pb_fallback=False) self.cachedir = cachedir self.urllist = urllist diff --git a/osc/meter.py b/osc/meter.py index d3a4d5d9..f699aa14 100644 --- a/osc/meter.py +++ b/osc/meter.py @@ -29,8 +29,30 @@ class PBTextMeter(object): 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 = None + TextMeter = NoPBTextMeter # vim: sw=4 et