From 4a02c44bbe7457249caeb07464e240b6bc035cc0 Mon Sep 17 00:00:00 2001 From: dol-sen Date: Mon, 25 Apr 2011 00:03:20 -0700 Subject: [PATCH] more cleanup of importing logging. Use the one defined or passed in to in main(). --- pym/gentoolkit/revdep_rebuild/analyse.py | 11 ++++++++--- pym/gentoolkit/revdep_rebuild/cache.py | 14 +++++++++----- pym/gentoolkit/revdep_rebuild/collect.py | 5 +++-- pym/gentoolkit/revdep_rebuild/rebuild.py | 17 ++++++++++++----- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py index 5ee0c7b..521d8b9 100644 --- a/pym/gentoolkit/revdep_rebuild/analyse.py +++ b/pym/gentoolkit/revdep_rebuild/analyse.py @@ -3,8 +3,8 @@ import os import re import platform -import logging import glob + from portage.output import bold, red, blue, yellow, green, nocolor from stuff import scan @@ -114,7 +114,7 @@ def main_checks(found_libs, broken, dependencies, logger): return broken_pathes -def analyse(settings=None, logger=None, libraries=None, la_libraries=None, +def analyse(settings, logger, libraries=None, la_libraries=None, libraries_links=None, binaries=None, _libs_to_check=set()): """Main program body. It will collect all info and determine the pkgs needing rebuilding. @@ -143,7 +143,12 @@ def analyse(settings=None, logger=None, libraries=None, la_libraries=None, binaries = collect_binaries_from_dir(bin_dirs, masked_dirs, logger) if settings['USE_TMP_FILES']: - save_cache(to_save={'libraries':libraries, 'la_libraries':la_libraries, 'libraries_links':libraries_links, 'binaries':binaries}) + save_cache(logger=logger, + to_save={'libraries':libraries, 'la_libraries':la_libraries, + 'libraries_links':libraries_links, 'binaries':binaries + }, + temp_path=settings['DEFAULT_TMP_DIR'] + ) logger.debug('Found '+ str(len(libraries)) + ' libraries (+' + str(len(libraries_links)) + ' symlinks) and ' + str(len(binaries)) + ' binaries') diff --git a/pym/gentoolkit/revdep_rebuild/cache.py b/pym/gentoolkit/revdep_rebuild/cache.py index e1a8e11..8b1a8ed 100644 --- a/pym/gentoolkit/revdep_rebuild/cache.py +++ b/pym/gentoolkit/revdep_rebuild/cache.py @@ -2,7 +2,7 @@ import os import time -import logging + from portage.output import red from settings import DEFAULTS @@ -29,7 +29,7 @@ def read_cache(temp_path=DEFAULTS['DEFAULT_TMP_DIR']): return (ret['libraries'], ret['la_libraries'], ret['libraries_links'], ret['binaries']) -def save_cache(logger=logging, to_save={}, temp_path=DEFAULTS['DEFAULT_TMP_DIR']): +def save_cache(logger, to_save={}, temp_path=DEFAULTS['DEFAULT_TMP_DIR']): ''' Tries to store caching information. @param logger @param to_save have to be dict with keys: libraries, la_libraries, libraries_links and binaries @@ -87,6 +87,7 @@ if __name__ == '__main__': print 'Preparing cache ... ' from collect import * + import logging bin_dirs, lib_dirs = prepare_search_dirs() @@ -95,9 +96,12 @@ if __name__ == '__main__': bin_dirs = bin_dirs.union(ld) masked_dirs = masked_dirs.union(set(['/lib/modules', '/lib32/modules', '/lib64/modules',])) - libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs) - binaries = collect_binaries_from_dir(bin_dirs, masked_dirs) + libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs, logging) + binaries = collect_binaries_from_dir(bin_dirs, masked_dirs, logging) - save_cache(to_save={'libraries':libraries, 'la_libraries':la_libraries, 'libraries_links':libraries_links, 'binaries':binaries}) + save_cache(logger=logging, + to_save={'libraries':libraries, 'la_libraries':la_libraries, + 'libraries_links':libraries_links, 'binaries':binaries} + ) print 'Done.' diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py index 735857b..b408edc 100644 --- a/pym/gentoolkit/revdep_rebuild/collect.py +++ b/pym/gentoolkit/revdep_rebuild/collect.py @@ -4,7 +4,7 @@ import re import os import glob import stat -import logging + import portage from portage.output import bold, red, blue, yellow, green, nocolor @@ -185,7 +185,7 @@ def collect_libraries_from_dir(dirs, mask, logger): return (found_files, found_la_files, found_symlinks, symlink_pairs) -def collect_binaries_from_dir(dirs, mask, logger=logging): +def collect_binaries_from_dir(dirs, mask, logger): ''' Collects all binaries from specified list of directories. mask is list of pathes, that are ommited in scanning, can be eighter single file or entire directory Returns list of binaries @@ -229,6 +229,7 @@ def collect_binaries_from_dir(dirs, mask, logger=logging): if __name__ == '__main__': + import logging bin_dirs, lib_dirs = prepare_search_dirs(logging) masked_dirs, masked_files, ld = parse_revdep_config() diff --git a/pym/gentoolkit/revdep_rebuild/rebuild.py b/pym/gentoolkit/revdep_rebuild/rebuild.py index 6185e0c..6c08f5b 100644 --- a/pym/gentoolkit/revdep_rebuild/rebuild.py +++ b/pym/gentoolkit/revdep_rebuild/rebuild.py @@ -169,13 +169,14 @@ def rebuild(logger, assigned, settings): # Runs from here -def main(settings=None): +def main(settings=None, logger=None): if settings is None: print("NO Input settings, using defaults...") settings = DEFAULTS.copy() - logger = init_logger(settings) + if logger is None: + logger = init_logger(settings) _libs_to_check = settings['library'] @@ -199,9 +200,15 @@ def main(settings=None): settings['PRETEND'] = True analyze_cache = {} - if settings['USE_TMP_FILES'] and check_temp_files(): - libraries, la_libraries, libraries_links, binaries = read_cache() - assigned = analyse(libraries=libraries, la_libraries=la_libraries, + if settings['USE_TMP_FILES'] \ + and check_temp_files(settings['DEFAULT_TMP_DIR']): + libraries, la_libraries, libraries_links, binaries = read_cache( + settings['DEFAULT_TMP_DIR']) + assigned = analyse( + settings=settings, + logger=logger, + libraries=libraries, + la_libraries=la_libraries, libraries_links=libraries_links, binaries=binaries, _libs_to_check=_libs_to_check) -- 2.26.2