More progress bar usage
This commit is contained in:
parent
5e33d025a3
commit
993005da61
@ -52,6 +52,10 @@ RUNNER_CLS_MAPPING = {
|
||||
# Where symlinks will go
|
||||
BASE_LINK_DIR = "/etc"
|
||||
|
||||
# Progress bar titles
|
||||
UNINSTALL_TITLE = utils.color_text('Uninstalling', 'blue')
|
||||
INSTALL_TITLE = utils.color_text('Installing', 'blue')
|
||||
|
||||
|
||||
class ComponentBase(object):
|
||||
def __init__(self,
|
||||
@ -188,7 +192,7 @@ 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)))
|
||||
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):
|
||||
self.tracewriter.package_installed(p)
|
||||
self.packager.install(p)
|
||||
@ -300,7 +304,7 @@ 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))
|
||||
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):
|
||||
self.tracewriter.pip_installed(p)
|
||||
pip.install(p, self.distro)
|
||||
@ -390,12 +394,17 @@ class PkgUninstallComponent(ComponentBase):
|
||||
pass
|
||||
|
||||
def _uninstall_pkgs(self):
|
||||
pkgsfull = self.tracereader.packages_installed()
|
||||
if pkgsfull:
|
||||
pkg_names = set([p['name'] for p in pkgsfull])
|
||||
pkgs = self.tracereader.packages_installed()
|
||||
if pkgs:
|
||||
pkg_names = set([p['name'] for p in pkgs])
|
||||
LOG.info("Potentially removing %s packages (%s)",
|
||||
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)",
|
||||
len(which_removed), ", ".join(which_removed))
|
||||
|
||||
@ -438,7 +447,10 @@ class PythonUninstallComponent(PkgUninstallComponent):
|
||||
if pips:
|
||||
names = set([p['name'] for p in pips])
|
||||
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):
|
||||
pylisting = self.tracereader.py_listing()
|
||||
|
@ -31,10 +31,11 @@ class Packager(object):
|
||||
def install(self, pkg):
|
||||
raise NotImplementedError()
|
||||
|
||||
def remove_batch(self, pkgs):
|
||||
if not self.keep_packages:
|
||||
return self._remove_batch(pkgs)
|
||||
return list()
|
||||
def remove(self, pkg):
|
||||
if self.keep_packages:
|
||||
return False
|
||||
else:
|
||||
return self._remove(pkg)
|
||||
|
||||
def pre_install(self, pkgs, params=None):
|
||||
for info in pkgs:
|
||||
@ -52,5 +53,5 @@ class Packager(object):
|
||||
info['name'])
|
||||
utils.execute_template(*cmds, params=params)
|
||||
|
||||
def _remove_batch(self, pkgs):
|
||||
def _remove(self, pkg):
|
||||
raise NotImplementedError()
|
||||
|
@ -57,28 +57,19 @@ class AptPackager(pack.Packager):
|
||||
env_overrides=ENV_ADDITIONS,
|
||||
**kargs)
|
||||
|
||||
def _remove_batch(self, pkgs):
|
||||
cmds = []
|
||||
which_removed = []
|
||||
for info in pkgs:
|
||||
name = info['name']
|
||||
removable = info.get('removable', True)
|
||||
def _remove(self, pkg):
|
||||
removable = pkg.get('removable', True)
|
||||
if not removable:
|
||||
continue
|
||||
if self._remove_special(name, info):
|
||||
which_removed.append(name)
|
||||
continue
|
||||
pkg_full = self._format_pkg_name(name, info.get("version"))
|
||||
if pkg_full:
|
||||
cmds.append(pkg_full)
|
||||
which_removed.append(name)
|
||||
if cmds:
|
||||
cmd = APT_DO_REMOVE + cmds
|
||||
return False
|
||||
name = pkg['name']
|
||||
if self._remove_special(name, pkg):
|
||||
return True
|
||||
pkg_full = self._format_pkg_name(name, pkg.get("version"))
|
||||
cmd = APT_DO_REMOVE + [pkg_full]
|
||||
self._execute_apt(cmd)
|
||||
if which_removed and self.auto_remove:
|
||||
cmd = APT_AUTOREMOVE
|
||||
self._execute_apt(cmd)
|
||||
return which_removed
|
||||
if self.auto_remove:
|
||||
self._execute_apt(APT_AUTOREMOVE)
|
||||
return True
|
||||
|
||||
def install(self, pkg):
|
||||
name = pkg['name']
|
||||
@ -86,7 +77,6 @@ class AptPackager(pack.Packager):
|
||||
return
|
||||
else:
|
||||
pkg_full = self._format_pkg_name(name, pkg.get("version"))
|
||||
if pkg_full:
|
||||
cmd = APT_INSTALL + [pkg_full]
|
||||
self._execute_apt(cmd)
|
||||
|
||||
|
@ -58,25 +58,19 @@ class YumPackager(pack.Packager):
|
||||
if self._install_special(name, pkg):
|
||||
return
|
||||
else:
|
||||
full_pkg_name = self._format_pkg_name(name, pkg.get("version"))
|
||||
cmd = YUM_INSTALL + [full_pkg_name]
|
||||
pkg_full = self._format_pkg_name(name, pkg.get("version"))
|
||||
cmd = YUM_INSTALL + [pkg_full]
|
||||
self._execute_yum(cmd)
|
||||
|
||||
def _remove_batch(self, pkgs):
|
||||
pkg_full_names = []
|
||||
which_removed = []
|
||||
for info in pkgs:
|
||||
name = info['name']
|
||||
removable = info.get('removable', True)
|
||||
def _remove(self, pkg):
|
||||
removable = pkg.get('removable', True)
|
||||
if not removable:
|
||||
continue
|
||||
if self._remove_special(name, info):
|
||||
which_removed.append(name)
|
||||
return False
|
||||
name = pkg['name']
|
||||
if self._remove_special(name, pkg):
|
||||
return True
|
||||
else:
|
||||
full_pkg_name = self._format_pkg_name(name, info.get("version"))
|
||||
pkg_full_names.append(full_pkg_name)
|
||||
which_removed.append(name)
|
||||
if pkg_full_names:
|
||||
cmd = YUM_REMOVE + pkg_full_names
|
||||
pkg_full = self._format_pkg_name(name, pkg.get("version"))
|
||||
cmd = YUM_REMOVE + [pkg_full]
|
||||
self._execute_yum(cmd)
|
||||
return which_removed
|
||||
return True
|
||||
|
@ -41,17 +41,16 @@ def install(pip, distro):
|
||||
sh.execute(*real_cmd, run_as_root=True)
|
||||
|
||||
|
||||
def uninstall_batch(pips, distro, skip_errors=True):
|
||||
names = set([p['name'] for p in pips])
|
||||
def uninstall(pip, distro, skip_errors=True):
|
||||
root_cmd = distro.get_command('pip')
|
||||
for name in names:
|
||||
name = pip['name']
|
||||
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)]
|
||||
sh.execute(*cmd, run_as_root=True)
|
||||
except excp.ProcessExecutionError:
|
||||
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))
|
||||
else:
|
||||
raise
|
||||
|
Loading…
Reference in New Issue
Block a user