From 5e33d025a318b688fd64b4b474fd1e0a3c09542f Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sat, 17 Mar 2012 00:21:07 -0700 Subject: [PATCH] A nice progress bar when installing our long running pips/pkgs --- devstack/component.py | 16 ++++++++++------ devstack/utils.py | 22 ++++++++++++++++++++-- tools/pip-requires | 1 + 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/devstack/component.py b/devstack/component.py index c8b8967d..76ee7e94 100644 --- a/devstack/component.py +++ b/devstack/component.py @@ -188,9 +188,11 @@ class PkgInstallComponent(ComponentBase): if pkgs: pkg_names = set([p['name'] for p in pkgs]) LOG.info("Setting up %s packages (%s)" % (len(pkg_names), ", ".join(pkg_names))) - for p in pkgs: - self.tracewriter.package_installed(p) - self.packager.install(p) + with utils.progress_bar('Packages', len(pkgs)) as p_bar: + for (i, p) in enumerate(pkgs): + self.tracewriter.package_installed(p) + self.packager.install(p) + p_bar.update(i + 1) else: LOG.info('No packages to install for %s', self.component_name) @@ -298,9 +300,11 @@ class PythonInstallComponent(PkgInstallComponent): if pips: pip_names = set([p['name'] for p in pips]) LOG.info("Setting up %s pips (%s)", len(pip_names), ", ".join(pip_names)) - for p in pips: - self.tracewriter.pip_installed(p) - pip.install(p, self.distro) + with utils.progress_bar('Pips', len(pips)) as p_bar: + for (i, p) in enumerate(pips): + self.tracewriter.pip_installed(p) + pip.install(p, self.distro) + p_bar.update(i + 1) def _install_python_setups(self): pydirs = self._get_python_directories() diff --git a/devstack/utils.py b/devstack/utils.py index 931facc8..e472ad77 100644 --- a/devstack/utils.py +++ b/devstack/utils.py @@ -17,14 +17,17 @@ # License for the specific language governing permissions and limitations # under the License. -import distutils.version import json -import netifaces import os import random import re import socket import sys +import contextlib + +import distutils.version +import netifaces +import progressbar import termcolor from devstack import colorlog @@ -139,6 +142,21 @@ def to_bytes(text): return byte_val +@contextlib.contextmanager +def progress_bar(name, max_am): + widgets = [ + '%s: ' % (name), progressbar.Percentage(), + ' ', progressbar.Bar(), + ' ', progressbar.ETA(), + ] + p_bar = progressbar.ProgressBar(maxval=max_am, widgets=widgets) + p_bar.start() + try: + yield p_bar + finally: + p_bar.finish() + + def import_module(module_name, quiet=True): try: __import__(module_name) diff --git a/tools/pip-requires b/tools/pip-requires index b46e07a1..ddf8c666 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -5,6 +5,7 @@ netifaces termcolor pyyaml # reading data files +progressbar # Testing nose # for test discovery and console feedback