Allowed a logger to be based in for the log iterable

This commit is contained in:
Joshua Harlow 2012-03-28 21:46:21 -07:00
parent 25a1c6e4f5
commit 1fe80ffda4
3 changed files with 34 additions and 17 deletions

View File

@ -180,7 +180,8 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
def download(self):
download_locs = self._get_real_download_locations()
uris = [loc['uri'] for loc in download_locs]
utils.log_iterable(uris, header="Downloading from %s uris" % (len(uris)))
utils.log_iterable(uris, logger=LOG,
header="Downloading from %s uris" % (len(uris)))
for info in download_locs:
# Extract da download!
uri = info['uri']
@ -228,7 +229,8 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
pkgs = self._get_packages()
if pkgs:
pkg_names = set([p['name'] for p in pkgs])
utils.log_iterable(pkg_names, header="Setting up %s distribution packages" % (len(pkg_names)))
utils.log_iterable(pkg_names, logger=LOG,
header="Setting up %s distribution packages" % (len(pkg_names)))
with utils.progress_bar(INSTALL_TITLE, len(pkgs)) as p_bar:
for (i, p) in enumerate(pkgs):
self.tracewriter.package_installed(p)
@ -280,7 +282,8 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
def _configure_files(self):
config_fns = self._get_config_files()
if config_fns:
utils.log_iterable(config_fns, header="Configuring %s files" % (len(config_fns)))
utils.log_iterable(config_fns, logger=LOG,
header="Configuring %s files" % (len(config_fns)))
for fn in config_fns:
parameters = self._get_param_map(fn)
tgt_fn = self._get_target_config_name(fn)
@ -341,7 +344,8 @@ class PythonInstallComponent(PkgInstallComponent):
pips = self._get_pips()
if pips:
pip_names = set([p['name'] for p in pips])
utils.log_iterable(pip_names, header="Setting up %s python packages" % (len(pip_names)))
utils.log_iterable(pip_names, logger=LOG,
header="Setting up %s python packages" % (len(pip_names)))
with utils.progress_bar(INSTALL_TITLE, len(pips)) as p_bar:
for (i, p) in enumerate(pips):
self.tracewriter.pip_installed(p)
@ -354,7 +358,8 @@ class PythonInstallComponent(PkgInstallComponent):
real_dirs = dict()
for (name, wkdir) in py_dirs.items():
real_dirs[name] = wkdir or self.app_dir
utils.log_iterable(real_dirs.values(), header="Setting up %s python directories" % (len(real_dirs)))
utils.log_iterable(real_dirs.values(), logger=LOG,
header="Setting up %s python directories" % (len(real_dirs)))
for (name, working_dir) in real_dirs.items():
self.tracewriter.dirs_made(*sh.mkdirslist(working_dir))
self.tracewriter.py_installed(name, working_dir)
@ -408,14 +413,16 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
def _unconfigure_links(self):
sym_files = self.tracereader.symlinks_made()
if sym_files:
utils.log_iterable(sym_files, header="Removing %s symlink files" % (len(sym_files)))
utils.log_iterable(sym_files, logger=LOG,
header="Removing %s symlink files" % (len(sym_files)))
for fn in sym_files:
sh.unlink(fn, run_as_root=True)
def _unconfigure_files(self):
cfg_files = self.tracereader.files_configured()
if cfg_files:
utils.log_iterable(cfg_files, header="Removing %s configuration files" % (len(cfg_files)))
utils.log_iterable(cfg_files, logger=LOG,
header="Removing %s configuration files" % (len(cfg_files)))
for fn in cfg_files:
sh.unlink(fn, run_as_root=True)
@ -445,12 +452,14 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
if packager.remove(p):
which_removed.add(p['name'])
p_bar.update(i + 1)
utils.log_iterable(which_removed, header="Actually removed %s packages" % (len(which_removed)))
utils.log_iterable(which_removed, logger=LOG,
header="Actually removed %s packages" % (len(which_removed)))
def _uninstall_touched_files(self):
files_touched = self.tracereader.files_touched()
if files_touched:
utils.log_iterable(files_touched, header="Removing %s touched files" % (len(files_touched)))
utils.log_iterable(files_touched, logger=LOG,
header="Removing %s touched files" % (len(files_touched)))
for fn in files_touched:
sh.unlink(fn, run_as_root=True)
@ -460,10 +469,12 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
dirs_made = [sh.abspth(d) for d in dirs_made]
if self.keep_old:
download_places = [path_location[0] for path_location in self.tracereader.download_locations()]
utils.log_iterable(download_places, header="Keeping %s download directories" % (len(download_places)))
utils.log_iterable(download_places, logger=LOG,
header="Keeping %s download directories" % (len(download_places)))
for download_place in download_places:
dirs_made = sh.remove_parents(download_place, dirs_made)
utils.log_iterable(dirs_made, header="Removing %s created directories" % (len(dirs_made)))
utils.log_iterable(dirs_made, logger=LOG,
header="Removing %s created directories" % (len(dirs_made)))
for dir_name in dirs_made:
sh.deldir(dir_name, run_as_root=True)
@ -481,7 +492,8 @@ class PythonUninstallComponent(PkgUninstallComponent):
pips = self.tracereader.pips_installed()
if pips:
pip_names = set([p['name'] for p in pips])
utils.log_iterable(pip_names, header="Uninstalling %s python packages" % (len(pip_names)))
utils.log_iterable(pip_names, logger=LOG,
header="Uninstalling %s python packages" % (len(pip_names)))
with utils.progress_bar(UNINSTALL_TITLE, len(pips), reverse=True) as p_bar:
for (i, p) in enumerate(pips):
pip.uninstall(p, self.distro)
@ -493,7 +505,8 @@ class PythonUninstallComponent(PkgUninstallComponent):
py_listing_dirs = set()
for (_, where) in py_listing:
py_listing_dirs.add(where)
utils.log_iterable(py_listing_dirs, header="Uninstalling %s python setups" % (len(py_listing_dirs)))
utils.log_iterable(py_listing_dirs, logger=LOG,
header="Uninstalling %s python setups" % (len(py_listing_dirs)))
for where in py_listing_dirs:
sh.execute(*PY_UNINSTALL, cwd=where, run_as_root=True)

View File

@ -145,7 +145,9 @@ class ActionRunner(object):
self._handle_prereq(persona, instances, root_dir)
component_order = self._order_components(persona.wanted_components)
LOG.info("Processing components for action %r", (self.NAME or "???"))
utils.log_iterable(component_order, header="Activating in the following order:")
utils.log_iterable(component_order,
header="Activating in the following order:",
logger=LOG)
self._verify_components(component_order, instances)
self._warm_components(component_order, instances)
self._run(persona, root_dir, component_order, instances)

View File

@ -152,11 +152,13 @@ def mark_unexecute_file(fn, kvs, comment_start='#'):
sh.chmod(fn, 0644)
def log_iterable(to_log, header=None):
def log_iterable(to_log, header=None, logger=None):
if not logger:
logger = LOG
if header:
LOG.info(header)
logger.info(header)
for c in to_log:
LOG.info("|-- %s", color_text(c, 'blue'))
logger.info("|-- %s", color_text(c, 'blue'))
@contextlib.contextmanager