diff options
author | 2011-04-24 23:18:44 -0700 | |
---|---|---|
committer | 2011-04-24 23:18:44 -0700 | |
commit | 8a83c1932eef3a025700f7d230a37b4fe0883794 (patch) | |
tree | 6ee47f76286764f8c82719d844d6810c6c3f92fa | |
parent | new /bin/revdep-ng script. revamp rebuild.py for a better api. (diff) | |
download | gentoolkit-8a83c1932eef3a025700f7d230a37b4fe0883794.tar.gz gentoolkit-8a83c1932eef3a025700f7d230a37b4fe0883794.tar.bz2 gentoolkit-8a83c1932eef3a025700f7d230a37b4fe0883794.zip |
migrate away from a global SETTINGS usage.
Better for tests and api usability.
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/analyse.py | 21 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/assign.py | 10 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/cache.py | 8 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/collect.py | 15 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/settings.py | 17 |
5 files changed, 40 insertions, 31 deletions
diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py index a9ac753..5ee0c7b 100644 --- a/pym/gentoolkit/revdep_rebuild/analyse.py +++ b/pym/gentoolkit/revdep_rebuild/analyse.py @@ -11,11 +11,9 @@ from stuff import scan from collect import prepare_search_dirs, parse_revdep_config, collect_libraries_from_dir, collect_binaries_from_dir from assign import assign_packages from cache import save_cache -from settings import SETTINGS - -def prepare_checks(files_to_check, libraries, bits): +def prepare_checks(files_to_check, libraries, bits, cmd_max_args): ''' Calls scanelf for all files_to_check, then returns found libraries and dependencies ''' @@ -23,7 +21,7 @@ def prepare_checks(files_to_check, libraries, bits): dependencies = [] # list of lists of files (from file_to_check) that uses # library (for dependencies[id] and libs[id] => id==id) - for line in scan(['-M', str(bits), '-nBF', '%F %n'], files_to_check, SETTINGS['CMD_MAX_ARGS']): + for line in scan(['-M', str(bits), '-nBF', '%F %n'], files_to_check, cmd_max_args): #call_program(['scanelf', '-M', str(bits), '-nBF', '%F %n',]+files_to_check).strip().split('\n'): r = line.strip().split(' ') if len(r) < 2: # no dependencies? @@ -116,7 +114,8 @@ def main_checks(found_libs, broken, dependencies, logger): return broken_pathes -def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=None, binaries=None, _libs_to_check=set()): +def analyse(settings=None, logger=None, 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. @@ -132,9 +131,9 @@ def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=N #TODO: add partial cache (for ex. only libraries) when found for some reason logger.warn(green(' * ') + bold('Collecting system binaries and libraries')) - bin_dirs, lib_dirs = prepare_search_dirs(logger) + bin_dirs, lib_dirs = prepare_search_dirs(logger, settings) - masked_dirs, masked_files, ld = parse_revdep_config() + masked_dirs, masked_files, ld = parse_revdep_config(settings['REVDEP_CONFDIR']) lib_dirs = lib_dirs.union(ld) bin_dirs = bin_dirs.union(ld) masked_dirs = masked_dirs.union(set(['/lib/modules', '/lib32/modules', '/lib64/modules',])) @@ -143,7 +142,7 @@ def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=N libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs, logger) binaries = collect_binaries_from_dir(bin_dirs, masked_dirs, logger) - if SETTINGS['USE_TMP_FILES']: + if settings['USE_TMP_FILES']: save_cache(to_save={'libraries':libraries, 'la_libraries':la_libraries, 'libraries_links':libraries_links, 'binaries':binaries}) @@ -170,10 +169,10 @@ def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=N for av_bits in glob.glob('/lib[0-9]*') or ('/lib32',): bits = int(av_bits[4:]) - _libraries = scan(['-M', str(bits), '-BF', '%F'], libraries+libraries_links, SETTINGS['CMD_MAX_ARGS']) + _libraries = scan(['-M', str(bits), '-BF', '%F'], libraries+libraries_links, settings['CMD_MAX_ARGS']) #call_program(['scanelf', '-M', str(bits), '-BF', '%F',] + libraries+libraries_links).strip().split('\n') - found_libs, dependencies = prepare_checks(libs_and_bins, _libraries, bits) + found_libs, dependencies = prepare_checks(libs_and_bins, _libraries, bits, settings['CMD_MAX_ARGS']) broken = find_broken(found_libs, _libraries, _libs_to_check) broken_la = extract_dependencies_from_la(la_libraries, _libraries, _libs_to_check, logger) @@ -186,7 +185,7 @@ def analyse(logger=logging, libraries=None, la_libraries=None, libraries_links=N logger.warn(green(' * ') + bold('Assign files to packages')) - return assign_packages(broken_pathes, logger) + return assign_packages(broken_pathes, logger, settings) diff --git a/pym/gentoolkit/revdep_rebuild/assign.py b/pym/gentoolkit/revdep_rebuild/assign.py index c4ae750..9eb177d 100644 --- a/pym/gentoolkit/revdep_rebuild/assign.py +++ b/pym/gentoolkit/revdep_rebuild/assign.py @@ -2,21 +2,19 @@ import os import re -import logging import portage from portage import portdb from portage.output import bold, red, blue, yellow, green, nocolor -from settings import SETTINGS -def assign_packages(broken, logger=logging): +def assign_packages(broken, logger, settings): ''' Finds and returns packages that owns files placed in broken. Broken is list of files ''' assigned = set() - for group in os.listdir(SETTINGS['PKG_DIR']): - for pkg in os.listdir(SETTINGS['PKG_DIR'] + group): - f = SETTINGS['PKG_DIR'] + group + '/' + pkg + '/CONTENTS' + for group in os.listdir(settings['PKG_DIR']): + for pkg in os.listdir(settings['PKG_DIR'] + group): + f = settings['PKG_DIR'] + group + '/' + pkg + '/CONTENTS' if os.path.exists(f): try: with open(f, 'r') as cnt: diff --git a/pym/gentoolkit/revdep_rebuild/cache.py b/pym/gentoolkit/revdep_rebuild/cache.py index 616ef79..e1a8e11 100644 --- a/pym/gentoolkit/revdep_rebuild/cache.py +++ b/pym/gentoolkit/revdep_rebuild/cache.py @@ -4,10 +4,10 @@ import os import time import logging from portage.output import red -from settings import SETTINGS +from settings import DEFAULTS -def read_cache(temp_path=SETTINGS['DEFAULT_TMP_DIR']): +def read_cache(temp_path=DEFAULTS['DEFAULT_TMP_DIR']): ''' Reads cache information needed by analyse function. This function does not checks if files exists nor timestamps, check_temp_files should be called first @@ -29,7 +29,7 @@ def read_cache(temp_path=SETTINGS['DEFAULT_TMP_DIR']): return (ret['libraries'], ret['la_libraries'], ret['libraries_links'], ret['binaries']) -def save_cache(logger=logging, to_save={}, temp_path=SETTINGS['DEFAULT_TMP_DIR']): +def save_cache(logger=logging, 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 @@ -53,7 +53,7 @@ def save_cache(logger=logging, to_save={}, temp_path=SETTINGS['DEFAULT_TMP_DIR'] -def check_temp_files(temp_path=SETTINGS['DEFAULT_TMP_DIR'], max_delay=3600): +def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600): ''' Checks if temporary files from previous run are still available and if they aren't too old @param temp_path is directory, where temporary files should be found diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py index 613749a..735857b 100644 --- a/pym/gentoolkit/revdep_rebuild/collect.py +++ b/pym/gentoolkit/revdep_rebuild/collect.py @@ -7,10 +7,9 @@ import stat import logging import portage from portage.output import bold, red, blue, yellow, green, nocolor -from settings import SETTINGS -def parse_conf(conf_file=SETTINGS['DEFAULT_LD_FILE'], visited=None, logger=logging): +def parse_conf(conf_file, visited=None, logger=None): ''' Parses supplied conf_file for libraries pathes. conf_file is file or files to parse visited is set of files already parsed @@ -54,7 +53,7 @@ def parse_conf(conf_file=SETTINGS['DEFAULT_LD_FILE'], visited=None, logger=loggi return lib_dirs -def prepare_search_dirs(logger=logging): +def prepare_search_dirs(logger, settings): ''' Lookup for search dirs. Returns tuple with two lists, (list_of_bin_dirs, list_of_lib_dirs) ''' @@ -63,7 +62,7 @@ def prepare_search_dirs(logger=logging): lib_dirs = set(['/lib', '/usr/lib', ]) #try: - with open(os.path.join(portage.root, SETTINGS['DEFAULT_ENV_FILE']), 'r') as f: + with open(os.path.join(portage.root, settings['DEFAULT_ENV_FILE']), 'r') as f: for line in f.readlines(): line = line.strip() m = re.match("^export (ROOT)?PATH='([^']+)'", line) @@ -72,11 +71,11 @@ def prepare_search_dirs(logger=logging): #except EnvironmentError: #logger.debug(yellow('Could not open file %s' % f)) - lib_dirs = parse_conf(logger=logger) + lib_dirs = parse_conf(settings['DEFAULT_LD_FILE'], logger=logger) return (bin_dirs, lib_dirs) -def parse_revdep_config(): +def parse_revdep_config(revdep_confdir): ''' Parses all files under /etc/revdep-rebuild/ and returns tuple of: (masked_dirs, masked_files, search_dirs)''' @@ -85,7 +84,7 @@ def parse_revdep_config(): masked_files = set() #TODO: remove hard-coded path - for f in os.listdir(SETTINGS['REVDEP_CONFDIR']): + for f in os.listdir(revdep_confdir): for line in open(os.path.join('/etc/revdep-rebuild', f)): line = line.strip() if not line.startswith('#'): #first check for comment, we do not want to regex all lines @@ -110,7 +109,7 @@ def parse_revdep_config(): return (masked_dirs, masked_files, search_dirs) -def collect_libraries_from_dir(dirs, mask, logger=logging): +def collect_libraries_from_dir(dirs, mask, logger): ''' Collects all libraries from specified list of directories. mask is list of pathes, that are ommited in scanning, can be eighter single file or entire directory Returns tuple composed of: list of libraries, list of symlinks, and toupe with pair diff --git a/pym/gentoolkit/revdep_rebuild/settings.py b/pym/gentoolkit/revdep_rebuild/settings.py index b47cb3e..7747ac2 100644 --- a/pym/gentoolkit/revdep_rebuild/settings.py +++ b/pym/gentoolkit/revdep_rebuild/settings.py @@ -1,9 +1,10 @@ #!/usr/bin/python import os +import sys import portage -SETTINGS = { +DEFAULTS = { 'DEFAULT_LD_FILE': os.path.join(portage.root, 'etc/ld.so.conf'), 'DEFAULT_ENV_FILE': os.path.join(portage.root, 'etc/profile.env'), 'REVDEP_CONFDIR': os.path.join(portage.root, 'etc/revdep-rebuild/'), @@ -23,4 +24,16 @@ SETTINGS = { # can be set True from the cli with the --no-pretend option 'NO_PRETEND': False, 'VERBOSITY': 1, - } + + 'quiet': False, + 'nocolor': False, + 'library': set(), + 'no-progress': False, + 'debug': False, + 'no-ld-path': False, + 'no-order': False, + 'pass_through_options': '', + 'stdout': sys.stdout, + 'stdin': sys.stdin, + 'stderr': sys.stderr + } |