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:
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()

View File

@ -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)

View File

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