More progress bar usage

This commit is contained in:
Joshua Harlow 2012-03-17 00:43:30 -07:00
parent 5e33d025a3
commit 993005da61
5 changed files with 65 additions and 69 deletions

View File

@ -52,6 +52,10 @@ RUNNER_CLS_MAPPING = {
# Where symlinks will go # Where symlinks will go
BASE_LINK_DIR = "/etc" BASE_LINK_DIR = "/etc"
# Progress bar titles
UNINSTALL_TITLE = utils.color_text('Uninstalling', 'blue')
INSTALL_TITLE = utils.color_text('Installing', 'blue')
class ComponentBase(object): class ComponentBase(object):
def __init__(self, def __init__(self,
@ -188,7 +192,7 @@ 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)))
with utils.progress_bar('Packages', len(pkgs)) as p_bar: with utils.progress_bar(INSTALL_TITLE, len(pkgs)) as p_bar:
for (i, p) in enumerate(pkgs): for (i, p) in enumerate(pkgs):
self.tracewriter.package_installed(p) self.tracewriter.package_installed(p)
self.packager.install(p) self.packager.install(p)
@ -300,7 +304,7 @@ 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))
with utils.progress_bar('Pips', len(pips)) as p_bar: with utils.progress_bar(INSTALL_TITLE, len(pips)) as p_bar:
for (i, p) in enumerate(pips): for (i, p) in enumerate(pips):
self.tracewriter.pip_installed(p) self.tracewriter.pip_installed(p)
pip.install(p, self.distro) pip.install(p, self.distro)
@ -390,12 +394,17 @@ class PkgUninstallComponent(ComponentBase):
pass pass
def _uninstall_pkgs(self): def _uninstall_pkgs(self):
pkgsfull = self.tracereader.packages_installed() pkgs = self.tracereader.packages_installed()
if pkgsfull: if pkgs:
pkg_names = set([p['name'] for p in pkgsfull]) pkg_names = set([p['name'] for p in pkgs])
LOG.info("Potentially removing %s packages (%s)", LOG.info("Potentially removing %s packages (%s)",
len(pkg_names), ", ".join(pkg_names)) len(pkg_names), ", ".join(pkg_names))
which_removed = self.packager.remove_batch(pkgsfull) which_removed = set()
with utils.progress_bar(UNINSTALL_TITLE, len(pkgs)) as p_bar:
for (i, p) in enumerate(pkgs):
if self.packager.remove(p):
which_removed.add(p['name'])
p_bar.update(i + 1)
LOG.info("Actually removed %s packages (%s)", LOG.info("Actually removed %s packages (%s)",
len(which_removed), ", ".join(which_removed)) len(which_removed), ", ".join(which_removed))
@ -438,7 +447,10 @@ class PythonUninstallComponent(PkgUninstallComponent):
if pips: if pips:
names = set([p['name'] for p in pips]) names = set([p['name'] for p in pips])
LOG.info("Uninstalling %s python packages (%s)" % (len(names), ", ".join(names))) LOG.info("Uninstalling %s python packages (%s)" % (len(names), ", ".join(names)))
pip.uninstall_batch(pips, self.distro) with utils.progress_bar(UNINSTALL_TITLE, len(pips)) as p_bar:
for (i, p) in enumerate(pips):
pip.uninstall(p, self.distro)
p_bar.update(i + 1)
def _uninstall_python(self): def _uninstall_python(self):
pylisting = self.tracereader.py_listing() pylisting = self.tracereader.py_listing()

View File

@ -31,10 +31,11 @@ class Packager(object):
def install(self, pkg): def install(self, pkg):
raise NotImplementedError() raise NotImplementedError()
def remove_batch(self, pkgs): def remove(self, pkg):
if not self.keep_packages: if self.keep_packages:
return self._remove_batch(pkgs) return False
return list() else:
return self._remove(pkg)
def pre_install(self, pkgs, params=None): def pre_install(self, pkgs, params=None):
for info in pkgs: for info in pkgs:
@ -52,5 +53,5 @@ class Packager(object):
info['name']) info['name'])
utils.execute_template(*cmds, params=params) utils.execute_template(*cmds, params=params)
def _remove_batch(self, pkgs): def _remove(self, pkg):
raise NotImplementedError() raise NotImplementedError()

View File

@ -57,28 +57,19 @@ class AptPackager(pack.Packager):
env_overrides=ENV_ADDITIONS, env_overrides=ENV_ADDITIONS,
**kargs) **kargs)
def _remove_batch(self, pkgs): def _remove(self, pkg):
cmds = [] removable = pkg.get('removable', True)
which_removed = []
for info in pkgs:
name = info['name']
removable = info.get('removable', True)
if not removable: if not removable:
continue return False
if self._remove_special(name, info): name = pkg['name']
which_removed.append(name) if self._remove_special(name, pkg):
continue return True
pkg_full = self._format_pkg_name(name, info.get("version")) pkg_full = self._format_pkg_name(name, pkg.get("version"))
if pkg_full: cmd = APT_DO_REMOVE + [pkg_full]
cmds.append(pkg_full)
which_removed.append(name)
if cmds:
cmd = APT_DO_REMOVE + cmds
self._execute_apt(cmd) self._execute_apt(cmd)
if which_removed and self.auto_remove: if self.auto_remove:
cmd = APT_AUTOREMOVE self._execute_apt(APT_AUTOREMOVE)
self._execute_apt(cmd) return True
return which_removed
def install(self, pkg): def install(self, pkg):
name = pkg['name'] name = pkg['name']
@ -86,7 +77,6 @@ class AptPackager(pack.Packager):
return return
else: else:
pkg_full = self._format_pkg_name(name, pkg.get("version")) pkg_full = self._format_pkg_name(name, pkg.get("version"))
if pkg_full:
cmd = APT_INSTALL + [pkg_full] cmd = APT_INSTALL + [pkg_full]
self._execute_apt(cmd) self._execute_apt(cmd)

View File

@ -58,25 +58,19 @@ class YumPackager(pack.Packager):
if self._install_special(name, pkg): if self._install_special(name, pkg):
return return
else: else:
full_pkg_name = self._format_pkg_name(name, pkg.get("version")) pkg_full = self._format_pkg_name(name, pkg.get("version"))
cmd = YUM_INSTALL + [full_pkg_name] cmd = YUM_INSTALL + [pkg_full]
self._execute_yum(cmd) self._execute_yum(cmd)
def _remove_batch(self, pkgs): def _remove(self, pkg):
pkg_full_names = [] removable = pkg.get('removable', True)
which_removed = []
for info in pkgs:
name = info['name']
removable = info.get('removable', True)
if not removable: if not removable:
continue return False
if self._remove_special(name, info): name = pkg['name']
which_removed.append(name) if self._remove_special(name, pkg):
return True
else: else:
full_pkg_name = self._format_pkg_name(name, info.get("version")) pkg_full = self._format_pkg_name(name, pkg.get("version"))
pkg_full_names.append(full_pkg_name) cmd = YUM_REMOVE + [pkg_full]
which_removed.append(name)
if pkg_full_names:
cmd = YUM_REMOVE + pkg_full_names
self._execute_yum(cmd) self._execute_yum(cmd)
return which_removed return True

View File

@ -41,17 +41,16 @@ def install(pip, distro):
sh.execute(*real_cmd, run_as_root=True) sh.execute(*real_cmd, run_as_root=True)
def uninstall_batch(pips, distro, skip_errors=True): def uninstall(pip, distro, skip_errors=True):
names = set([p['name'] for p in pips])
root_cmd = distro.get_command('pip') root_cmd = distro.get_command('pip')
for name in names: name = pip['name']
try: try:
LOG.debug("Uninstalling python package (%s)" % (name)) LOG.audit("Uninstalling python package (%s) using pip command (%s)" % (name))
cmd = [root_cmd, 'uninstall'] + PIP_UNINSTALL_CMD_OPTS + [str(name)] cmd = [root_cmd, 'uninstall'] + PIP_UNINSTALL_CMD_OPTS + [str(name)]
sh.execute(*cmd, run_as_root=True) sh.execute(*cmd, run_as_root=True)
except excp.ProcessExecutionError: except excp.ProcessExecutionError:
if skip_errors: if skip_errors:
LOG.warn(("Ignoring execution error that occured when uninstalling pip %s!" LOG.debug(("Ignoring execution error that occured when uninstalling pip %s!"
" (this may be ok if it was uninstalled by a previous component)") % (name)) " (this may be ok if it was uninstalled by a previous component)") % (name))
else: else:
raise raise