A nice progress bar when installing our long running pips/pkgs

This commit is contained in:
Joshua Harlow 2012-03-17 00:21:07 -07:00
parent fa09f94879
commit 5e33d025a3
3 changed files with 31 additions and 8 deletions

View File

@ -188,9 +188,11 @@ class PkgInstallComponent(ComponentBase):
if pkgs: if pkgs:
pkg_names = set([p['name'] for p in pkgs]) pkg_names = set([p['name'] for p in pkgs])
LOG.info("Setting up %s packages (%s)" % (len(pkg_names), ", ".join(pkg_names))) LOG.info("Setting up %s packages (%s)" % (len(pkg_names), ", ".join(pkg_names)))
for p in pkgs: with utils.progress_bar('Packages', len(pkgs)) as p_bar:
self.tracewriter.package_installed(p) for (i, p) in enumerate(pkgs):
self.packager.install(p) self.tracewriter.package_installed(p)
self.packager.install(p)
p_bar.update(i + 1)
else: else:
LOG.info('No packages to install for %s', LOG.info('No packages to install for %s',
self.component_name) self.component_name)
@ -298,9 +300,11 @@ class PythonInstallComponent(PkgInstallComponent):
if pips: if pips:
pip_names = set([p['name'] for p in pips]) pip_names = set([p['name'] for p in pips])
LOG.info("Setting up %s pips (%s)", len(pip_names), ", ".join(pip_names)) LOG.info("Setting up %s pips (%s)", len(pip_names), ", ".join(pip_names))
for p in pips: with utils.progress_bar('Pips', len(pips)) as p_bar:
self.tracewriter.pip_installed(p) for (i, p) in enumerate(pips):
pip.install(p, self.distro) self.tracewriter.pip_installed(p)
pip.install(p, self.distro)
p_bar.update(i + 1)
def _install_python_setups(self): def _install_python_setups(self):
pydirs = self._get_python_directories() pydirs = self._get_python_directories()

View File

@ -17,14 +17,17 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import distutils.version
import json import json
import netifaces
import os import os
import random import random
import re import re
import socket import socket
import sys import sys
import contextlib
import distutils.version
import netifaces
import progressbar
import termcolor import termcolor
from devstack import colorlog from devstack import colorlog
@ -139,6 +142,21 @@ def to_bytes(text):
return byte_val 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): def import_module(module_name, quiet=True):
try: try:
__import__(module_name) __import__(module_name)

View File

@ -5,6 +5,7 @@
netifaces netifaces
termcolor termcolor
pyyaml # reading data files pyyaml # reading data files
progressbar
# Testing # Testing
nose # for test discovery and console feedback nose # for test discovery and console feedback