Use more log iterable

This commit is contained in:
Joshua Harlow 2012-03-28 17:31:12 -07:00
parent 51d65678d9
commit 25a1c6e4f5
2 changed files with 57 additions and 65 deletions

View File

@ -178,18 +178,17 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
return real_locations return real_locations
def download(self): def download(self):
download_am = 0 download_locs = self._get_real_download_locations()
for info in self._get_real_download_locations(): uris = [loc['uri'] for loc in download_locs]
utils.log_iterable(uris, header="Downloading from %s uris" % (len(uris)))
for info in download_locs:
# Extract da download! # Extract da download!
uri = info['uri'] uri = info['uri']
target_loc = info['target'] target_loc = info['target']
branch = info['branch'] branch = info['branch']
if not uri or not target_loc:
continue
# Activate da download! # Activate da download!
self.tracewriter.download_happened(target_loc, uri) self.tracewriter.download_happened(target_loc, uri)
dirs_made = self._do_download(uri, target_loc, branch) dirs_made = self._do_download(uri, target_loc, branch)
download_am += 1
# Here we ensure this is always added so that # Here we ensure this is always added so that
# if a keep old happens then this of course # if a keep old happens then this of course
# won't be recreated, but if u uninstall without keeping old # won't be recreated, but if u uninstall without keeping old
@ -198,7 +197,7 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
if target_loc not in dirs_made: if target_loc not in dirs_made:
dirs_made.append(target_loc) dirs_made.append(target_loc)
self.tracewriter.dirs_made(*dirs_made) self.tracewriter.dirs_made(*dirs_made)
return download_am return len(download_locs)
def _do_download(self, uri, target_dir, branch): def _do_download(self, uri, target_dir, branch):
return down.GitDownloader(self.distro, uri, target_dir, branch).download() return down.GitDownloader(self.distro, uri, target_dir, branch).download()
@ -225,13 +224,11 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
return pkg_list return pkg_list
def install(self): def install(self):
LOG.debug('Preparing to install packages for %r', LOG.debug('Preparing to install packages for %r', self.component_name)
self.component_name)
pkgs = self._get_packages() pkgs = self._get_packages()
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)", utils.log_iterable(pkg_names, header="Setting up %s distribution packages" % (len(pkg_names)))
len(pkg_names), ", ".join(pkg_names))
with utils.progress_bar(INSTALL_TITLE, 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)
@ -239,8 +236,7 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
packager.install(p) packager.install(p)
p_bar.update(i + 1) p_bar.update(i + 1)
else: else:
LOG.info('No packages to install for %r', LOG.info('No packages to install for %r', self.component_name)
self.component_name)
return self.trace_dir return self.trace_dir
def pre_install(self): def pre_install(self):
@ -282,10 +278,10 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
return links return links
def _configure_files(self): def _configure_files(self):
configs = self._get_config_files() config_fns = self._get_config_files()
if configs: if config_fns:
LOG.info("Configuring %s files", len(configs)) utils.log_iterable(config_fns, header="Configuring %s files" % (len(config_fns)))
for fn in configs: for fn in config_fns:
parameters = self._get_param_map(fn) parameters = self._get_param_map(fn)
tgt_fn = self._get_target_config_name(fn) tgt_fn = self._get_target_config_name(fn)
self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn))) self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn)))
@ -298,7 +294,7 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
LOG.info("Writing configuration file %r", tgt_fn) LOG.info("Writing configuration file %r", tgt_fn)
self.tracewriter.cfg_file_written(sh.write_file(tgt_fn, self.tracewriter.cfg_file_written(sh.write_file(tgt_fn,
contents)) contents))
return len(configs) return len(config_fns)
def _configure_symlinks(self): def _configure_symlinks(self):
links = self._get_symlinks() links = self._get_symlinks()
@ -335,7 +331,7 @@ class PythonInstallComponent(PkgInstallComponent):
pip_list = list(self.pips) pip_list = list(self.pips)
for name in self.desired_subsystems: for name in self.desired_subsystems:
if name in self.subsystem_info: if name in self.subsystem_info:
# Todo handle duplicates/version differences? # TODO handle duplicates/version differences?
LOG.debug("Extending pip list with pips for subsystem %r" % (name)) LOG.debug("Extending pip list with pips for subsystem %r" % (name))
subsystem_pips = self.subsystem_info[name].get('pips', list()) subsystem_pips = self.subsystem_info[name].get('pips', list())
pip_list.extend(subsystem_pips) pip_list.extend(subsystem_pips)
@ -345,7 +341,7 @@ class PythonInstallComponent(PkgInstallComponent):
pips = self._get_pips() pips = self._get_pips()
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)) utils.log_iterable(pip_names, header="Setting up %s python packages" % (len(pip_names)))
with utils.progress_bar(INSTALL_TITLE, 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)
@ -353,12 +349,13 @@ class PythonInstallComponent(PkgInstallComponent):
p_bar.update(i + 1) p_bar.update(i + 1)
def _install_python_setups(self): def _install_python_setups(self):
pydirs = self._get_python_directories() py_dirs = self._get_python_directories()
if pydirs: if py_dirs:
LOG.info("Setting up %s python directories (%s)", real_dirs = dict()
len(pydirs), pydirs) for (name, wkdir) in py_dirs.items():
for (name, wkdir) in pydirs.items(): real_dirs[name] = wkdir or self.app_dir
working_dir = wkdir or self.app_dir utils.log_iterable(real_dirs.values(), 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.dirs_made(*sh.mkdirslist(working_dir))
self.tracewriter.py_installed(name, working_dir) self.tracewriter.py_installed(name, working_dir)
(stdout, stderr) = sh.execute(*PY_INSTALL, (stdout, stderr) = sh.execute(*PY_INSTALL,
@ -409,19 +406,17 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
instance.unconfigure() instance.unconfigure()
def _unconfigure_links(self): def _unconfigure_links(self):
symfiles = self.tracereader.symlinks_made() sym_files = self.tracereader.symlinks_made()
if symfiles: if sym_files:
LOG.info("Removing %s symlink files (%s)", utils.log_iterable(sym_files, header="Removing %s symlink files" % (len(sym_files)))
len(symfiles), ", ".join(symfiles)) for fn in sym_files:
for fn in symfiles:
sh.unlink(fn, run_as_root=True) sh.unlink(fn, run_as_root=True)
def _unconfigure_files(self): def _unconfigure_files(self):
cfgfiles = self.tracereader.files_configured() cfg_files = self.tracereader.files_configured()
if cfgfiles: if cfg_files:
LOG.info("Removing %s configuration files (%s)", utils.log_iterable(cfg_files, header="Removing %s configuration files" % (len(cfg_files)))
len(cfgfiles), ", ".join(cfgfiles)) for fn in cfg_files:
for fn in cfgfiles:
sh.unlink(fn, run_as_root=True) sh.unlink(fn, run_as_root=True)
def uninstall(self): def uninstall(self):
@ -437,13 +432,12 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
def _uninstall_pkgs(self): def _uninstall_pkgs(self):
if self.keep_old: if self.keep_old:
LOG.info('Keep-old flag set, not removing packages') LOG.info('Keep-old flag set, not removing any packages.')
return return
pkgs = self.tracereader.packages_installed() pkgs = self.tracereader.packages_installed()
if pkgs: if pkgs:
pkg_names = set([p['name'] for p in pkgs]) pkg_names = set([p['name'] for p in pkgs])
LOG.info("Potentially removing %s packages (%s)", utils.log_iterable(pkg_names, header="Potentially removing %s packages" % (len(pkg_names)))
len(pkg_names), ", ".join(pkg_names))
which_removed = set() which_removed = set()
with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar: with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar:
for (i, p) in enumerate(pkgs): for (i, p) in enumerate(pkgs):
@ -451,32 +445,27 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
if packager.remove(p): if packager.remove(p):
which_removed.add(p['name']) which_removed.add(p['name'])
p_bar.update(i + 1) p_bar.update(i + 1)
LOG.info("Actually removed %s packages (%s)", utils.log_iterable(which_removed, header="Actually removed %s packages" % (len(which_removed)))
len(which_removed), ", ".join(which_removed))
def _uninstall_touched_files(self): def _uninstall_touched_files(self):
filestouched = self.tracereader.files_touched() files_touched = self.tracereader.files_touched()
if filestouched: if files_touched:
LOG.info("Removing %s touched files (%s)", utils.log_iterable(files_touched, header="Removing %s touched files" % (len(files_touched)))
len(filestouched), ", ".join(filestouched)) for fn in files_touched:
for fn in filestouched:
sh.unlink(fn, run_as_root=True) sh.unlink(fn, run_as_root=True)
def _uninstall_dirs(self): def _uninstall_dirs(self):
dirsmade = self.tracereader.dirs_made() dirs_made = self.tracereader.dirs_made()
if dirsmade: if dirs_made:
dirsmade = [sh.abspth(d) for d in dirsmade] dirs_made = [sh.abspth(d) for d in dirs_made]
if self.keep_old: if self.keep_old:
places = set() download_places = [path_location[0] for path_location in self.tracereader.download_locations()]
for (pth_loc, _) in self.tracereader.download_locations(): utils.log_iterable(download_places, header="Keeping %s download directories" % (len(download_places)))
places.add(pth_loc) for download_place in download_places:
LOG.info("Keeping %s download directories (%s)", dirs_made = sh.remove_parents(download_place, dirs_made)
len(places), ", ".join(sorted(places))) utils.log_iterable(dirs_made, header="Removing %s created directories" % (len(dirs_made)))
for download_place in places: for dir_name in dirs_made:
dirsmade = sh.remove_parents(download_place, dirsmade) sh.deldir(dir_name, run_as_root=True)
for dirname in dirsmade:
LOG.info("Removing created directory %r", dirname)
sh.deldir(dirname, run_as_root=True)
class PythonUninstallComponent(PkgUninstallComponent): class PythonUninstallComponent(PkgUninstallComponent):
@ -491,18 +480,21 @@ class PythonUninstallComponent(PkgUninstallComponent):
def _uninstall_pips(self): def _uninstall_pips(self):
pips = self.tracereader.pips_installed() pips = self.tracereader.pips_installed()
if pips: if pips:
names = set([p['name'] for p in pips]) pip_names = set([p['name'] for p in pips])
LOG.info("Uninstalling %s python packages (%s)" % (len(names), ", ".join(names))) utils.log_iterable(pip_names, header="Uninstalling %s python packages" % (len(pip_names)))
with utils.progress_bar(UNINSTALL_TITLE, len(pips), reverse=True) as p_bar: with utils.progress_bar(UNINSTALL_TITLE, len(pips), reverse=True) as p_bar:
for (i, p) in enumerate(pips): for (i, p) in enumerate(pips):
pip.uninstall(p, self.distro) pip.uninstall(p, self.distro)
p_bar.update(i + 1) p_bar.update(i + 1)
def _uninstall_python(self): def _uninstall_python(self):
pylisting = self.tracereader.py_listing() py_listing = self.tracereader.py_listing()
if pylisting: if py_listing:
LOG.info("Uninstalling %s python setups.", len(pylisting)) py_listing_dirs = set()
for (_, where) in pylisting: 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)))
for where in py_listing_dirs:
sh.execute(*PY_UNINSTALL, cwd=where, run_as_root=True) sh.execute(*PY_UNINSTALL, cwd=where, run_as_root=True)

View File

@ -152,7 +152,7 @@ def mark_unexecute_file(fn, kvs, comment_start='#'):
sh.chmod(fn, 0644) sh.chmod(fn, 0644)
def log_iterable(to_log, header=""): def log_iterable(to_log, header=None):
if header: if header:
LOG.info(header) LOG.info(header)
for c in to_log: for c in to_log: