From: dol-sen Date: Thu, 14 Jul 2011 01:37:51 +0000 (-0700) Subject: major pylint cleanup, 2 probable bugs fixed along the way. X-Git-Tag: gentoolkit-0.3.0.5~26 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=59abbce2ffb3a430f22d450a77f2fc91ac13274b;p=gentoolkit.git major pylint cleanup, 2 probable bugs fixed along the way. --- diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py index 5494270..f992db0 100644 --- a/pym/gentoolkit/revdep_rebuild/analyse.py +++ b/pym/gentoolkit/revdep_rebuild/analyse.py @@ -9,36 +9,42 @@ import re import platform import glob -from portage.output import bold, red, blue, yellow, green, nocolor +from portage.output import bold, blue, yellow, green from .stuff import scan -from .collect import prepare_search_dirs, parse_revdep_config, collect_libraries_from_dir, collect_binaries_from_dir +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 def prepare_checks(files_to_check, libraries, bits, cmd_max_args): - ''' Calls scanelf for all files_to_check, then returns found libraries and dependencies + ''' Calls scanelf for all files_to_check, + then returns found libraries and dependencies ''' - libs = [] # libs found by scanelf - dependencies = [] # list of lists of files (from file_to_check) that uses - # library (for dependencies[id] and libs[id] => id==id) + # libs found by scanelf + libs = [] + # list of lists of files (from file_to_check) that uses + # library (for dependencies[id] and libs[id] => id==id) + dependencies = [] + for line in scan( + ['-M', str(bits), '-nBF', '%F %n'], + files_to_check, 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? + parts = line.strip().split(' ') + if len(parts) < 2: # no dependencies? continue - deps = r[1].split(',') - for d in deps: - if d in libs: - i = libs.index(d) - dependencies[i].append(r[0]) + deps = parts[1].split(',') + for dep in deps: + if dep in libs: + index = libs.index(dep) + dependencies[index].append(parts[0]) else: - libs.append(d) - dependencies.append([r[0],]) + libs.append(dep) + dependencies.append([parts[0],]) return (libs, dependencies) @@ -47,25 +53,27 @@ def extract_dependencies_from_la(la, libraries, to_check, logger): broken = [] libnames = [] - for l in libraries: - m = re.match('.+\/(.+)\.(so|la|a)(\..+)?', l) - if m is not None: - ln = m.group(1) - if ln not in libnames: - libnames += [ln, ] - - for f in la: - if not os.path.exists(f): + for lib in libraries: + match = re.match('.+\/(.+)\.(so|la|a)(\..+)?', lib) + if match is not None: + libname = match.group(1) + if libname not in libnames: + libnames += [libname, ] + + for _file in la: + if not os.path.exists(_file): continue - for line in open(f, 'r').readlines(): + for line in open(_file, 'r').readlines(): line = line.strip() if line.startswith('dependency_libs='): - m = re.match("dependency_libs='([^']+)'", line) - if m is not None: - for el in m.group(1).split(' '): + match = re.match("dependency_libs='([^']+)'", line) + if match is not None: + for el in match.group(1).split(' '): el = el.strip() - if len(el) < 1 or el.startswith('-L') or el.startswith('-R'): + if (len(el) < 1 or el.startswith('-L') + or el.startswith('-R') + ): continue if el.startswith('-l') and 'lib'+el[2:] in libnames: @@ -82,8 +90,9 @@ def extract_dependencies_from_la(la, libraries, to_check, logger): if not _break: continue - logger.info(yellow(' * ') + f + ' is broken (requires: ' + bold(el)+')') - broken.append(f) + logger.info(yellow(' * ') + _file + + ' is broken (requires: ' + bold(el)+')') + broken.append(_file) return broken @@ -94,39 +103,40 @@ def find_broken(found_libs, system_libraries, to_check): is list of library names. ''' - # join libraries and looking at it as string is way too faster than for-jumping + # join libraries and looking at it as string + # is way faster than for-jumping broken = [] - sl = '|'.join(system_libraries) + syslibs = '|'.join(system_libraries) if not to_check: - for f in found_libs: - if f+'|' not in sl: - broken.append(found_libs.index(f)) + for found in found_libs: + if found + '|' not in syslibs: + broken.append(found_libs.index(found)) else: for tc in to_check: - for f in found_libs: - if tc in f:# and f+'|' not in sl: - broken.append(found_libs.index(f)) + for found in found_libs: + if tc in found:# and found+'|' not in syslibs: + broken.append(found_libs.index(found)) return broken -def main_checks(found_libs, broken, dependencies, logger): +def main_checks(found_libs, broken_list, dependencies, logger): ''' Checks for broken dependencies. found_libs have to be the same as returned by prepare_checks - broken is list of libraries found by scanelf + broken_list is list of libraries found by scanelf dependencies is the value returned by prepare_checks ''' broken_pathes = [] - for b in broken: - f = found_libs[b] - logger.info('Broken files that requires: ' + bold(f)) - for d in dependencies[b]: - logger.info(yellow(' * ') + d) - broken_pathes.append(d) + for broken in broken_list: + found = found_libs[broken] + logger.info('Broken files that requires: ' + bold(found)) + for dep_path in dependencies[broken]: + logger.info(yellow(' * ') + dep_path) + broken_pathes.append(dep_path) return broken_pathes @@ -142,20 +152,31 @@ def analyse(settings, logger, libraries=None, la_libraries=None, """ if libraries and la_libraries and libraries_links and binaries: - logger.info(blue(' * ') + bold('Found a valid cache, skipping collecting phase')) + logger.info(blue(' * ') + + bold('Found a valid cache, skipping collecting phase')) else: - #TODO: add partial cache (for ex. only libraries) when found for some reason + #TODO: add partial cache (for ex. only libraries) + # when found for some reason - logger.warn(green(' * ') + bold('Collecting system binaries and libraries')) + logger.warn(green(' * ') + + bold('Collecting system binaries and libraries')) bin_dirs, lib_dirs = prepare_search_dirs(logger, settings) - masked_dirs, masked_files, ld = parse_revdep_config(settings['REVDEP_CONFDIR']) + masked_dirs, masked_files, ld = \ + parse_revdep_config(settings['REVDEP_CONFDIR']) lib_dirs.update(ld) bin_dirs.update(ld) - masked_dirs = masked_dirs.union(set(['/lib/modules', '/lib32/modules', '/lib64/modules',])) + masked_dirs.update([ + '/lib/modules', + '/lib32/modules', + '/lib64/modules' + ] + ) - logger.info(green(' * ') + bold('Collecting dynamic linking informations')) - libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs, logger) + logger.info(green(' * ') + + bold('Collecting dynamic linking informations')) + 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']: @@ -167,17 +188,16 @@ def analyse(settings, logger, libraries=None, la_libraries=None, ) - logger.debug('Found '+ str(len(libraries)) + ' libraries (+' + str(len(libraries_links)) + ' symlinks) and ' + str(len(binaries)) + ' binaries') + logger.debug('Found '+ str(len(libraries)) + + ' libraries (+' + str(len(libraries_links)) + + ' symlinks) and ' + str(len(binaries)) + + ' binaries') logger.warn(green(' * ') + bold('Checking dynamic linking consistency')) - logger.debug('Search for ' + str(len(binaries)+len(libraries)) + ' within ' + str(len(libraries)+len(libraries_links))) + logger.debug('Search for ' + str(len(binaries)+len(libraries)) + + ' within ' + str(len(libraries)+len(libraries_links))) libs_and_bins = libraries+binaries - #l = [] - #for line in call_program(['scanelf', '-M', '64', '-BF', '%F',] + libraries).strip().split('\n'): - #l.append(line) - #libraries = l - found_libs = [] dependencies = [] @@ -195,21 +215,21 @@ def analyse(settings, logger, libraries=None, la_libraries=None, elif _bits.startswith('64'): bits = 64 - import time broken = [] 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 = libraries+libraries_links - found_libs, dependencies = prepare_checks(libs_and_bins, _libraries, bits, settings['CMD_MAX_ARGS']) + found_libs, dependencies = prepare_checks(libs_and_bins, + _libraries, bits, settings['CMD_MAX_ARGS']) broken = find_broken(found_libs, _libraries, _libs_to_check) bits /= 2 bits = int(bits) - broken_la = extract_dependencies_from_la(la_libraries, libraries+libraries_links, _libs_to_check, logger) + broken_la = extract_dependencies_from_la(la_libraries, + libraries+libraries_links, _libs_to_check, logger) broken_pathes = main_checks(found_libs, broken, dependencies, logger) diff --git a/pym/gentoolkit/revdep_rebuild/assign.py b/pym/gentoolkit/revdep_rebuild/assign.py index bbe409b..af82b27 100644 --- a/pym/gentoolkit/revdep_rebuild/assign.py +++ b/pym/gentoolkit/revdep_rebuild/assign.py @@ -10,8 +10,9 @@ import os import re import portage +from portage.versions import catpkgsplit from portage import portdb -from portage.output import bold, red, blue, yellow, green, nocolor +from portage.output import bold, red, yellow def assign_packages(broken, logger, settings): @@ -21,21 +22,23 @@ def assign_packages(broken, logger, settings): 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' - if os.path.exists(f): + _file = settings['PKG_DIR'] + group + '/' + pkg + '/CONTENTS' + if os.path.exists(_file): try: - with open(f, 'r') as cnt: + with open(_file, 'r') as cnt: for line in cnt: - m = re.match('^obj (/[^ ]+)', line) - if m is not None: - m = m.group(1) - if m in broken: + matches = re.match('^obj (/[^ ]+)', line) + if matches is not None: + match = matches.group(1) + if match in broken: found = group+'/'+pkg if found not in assigned: assigned.add(found) - logger.info('\t' + m + ' -> ' + bold(found)) - except Exception as e: - logger.warn(red(' !! Failed to read ' + f)) + logger.info('\t' + match + ' -> ' + + bold(found)) + except Exception as ex: + logger.warn(red(' !! Failed to read ' + _file) + + " Original exception was:\n" + str(ex)) return assigned @@ -54,24 +57,24 @@ def get_best_match(cpv, cp, logger): logger.warn(yellow('Warning: ebuild "' + cpv + '" not found.')) logger.info('Looking for %s:%s' %(cp, slot)) try: - m = portdb.match('%s:%s' %(cp, slot)) + match = portdb.match('%s:%s' %(cp, slot)) except portage.exception.InvalidAtom: - m = None + match = None - if not m: - logger.warn(red('!!') + ' ' + yellow('Could not find ebuild for %s:%s' %(cp, slot))) + if not match: + logger.warn(red('!!') + ' ' + yellow( + 'Could not find ebuild for %s:%s' %(cp, slot))) slot = [''] - m = portdb.match(cp) - if not m: - logger.warn(red('!!') + ' ' + yellow('Could not find ebuild for ' + cp)) - return m, slot + match = portdb.match(cp) + if not match: + logger.warn(red('!!') + ' ' + + yellow('Could not find ebuild for ' + cp)) + return match, slot def get_slotted_cps(cpvs, logger): """Uses portage to reduce the cpv list into a cp:slot list and returns it """ - from portage.versions import catpkgsplit - from portage import portdb cps = [] for cpv in cpvs: @@ -80,9 +83,10 @@ def get_slotted_cps(cpvs, logger): try: slot = portdb.aux_get(cpv, ["SLOT"]) except KeyError: - m, slot = get_best_match(cpv, cp, logger) - if not m: - logger.warn(red("Installed package: %s is no longer available" %cp)) + match, slot = get_best_match(cpv, cp, logger) + if not match: + logger.warn(red("Installed package: " + "%s is no longer available" %cp)) continue if slot[0]: diff --git a/pym/gentoolkit/revdep_rebuild/cache.py b/pym/gentoolkit/revdep_rebuild/cache.py index 7dc9a8d..2bb9f59 100644 --- a/pym/gentoolkit/revdep_rebuild/cache.py +++ b/pym/gentoolkit/revdep_rebuild/cache.py @@ -18,53 +18,65 @@ def read_cache(temp_path=DEFAULTS['DEFAULT_TMP_DIR']): This function does not checks if files exists nor timestamps, check_temp_files should be called first @param temp_path: directory where all temp files should reside - @return tuple with values of: libraries, la_libraries, libraries_links, symlink_pairs, binaries + @return tuple with values of: + libraries, la_libraries, libraries_links, symlink_pairs, binaries ''' - ret = {'libraries':[], 'la_libraries':[], 'libraries_links':[], 'binaries':[]} + ret = { + 'libraries':[], + 'la_libraries':[], + 'libraries_links':[], + 'binaries':[] + } try: - for key,val in list(ret.items()): - f = open(os.path.join(temp_path, key)) - for line in f.readlines(): + for key, val in list(ret.items()): + _file = open(os.path.join(temp_path, key)) + for line in _file .readlines(): val.append(line.strip()) #libraries.remove('\n') - f.close() + _file .close() except EnvironmentError: pass - return (ret['libraries'], ret['la_libraries'], ret['libraries_links'], ret['binaries']) + return (ret['libraries'], ret['la_libraries'], + ret['libraries_links'], ret['binaries']) -def save_cache(logger, to_save={}, temp_path=DEFAULTS['DEFAULT_TMP_DIR']): +def save_cache(logger, to_save=None, 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 + @param to_save have to be dict with keys: + libraries, la_libraries, libraries_links and binaries ''' + + if to_save is None: + to_save = {} if not os.path.exists(temp_path): os.makedirs(temp_path) try: - f = open(os.path.join(temp_path, 'timestamp'), 'w') - f.write(str(int(time.time()))) - f.close() + _file = open(os.path.join(temp_path, 'timestamp'), 'w') + _file.write(str(int(time.time()))) + _file.close() - for key,val in list(to_save.items()): - f = open(os.path.join(temp_path, key), 'w') + for key, val in list(to_save.items()): + _file = open(os.path.join(temp_path, key), 'w') for line in val: - f.write(line + '\n') - f.close() + _file.write(line + '\n') + _file.close() except Exception as ex: logger.warn(red('Could not save cache: %s' %str(ex))) -def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600): +def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600, + logger=None): ''' 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 - @param max_delay is maximum time difference (in seconds) when those files - are still considered fresh and useful + @param max_delay is maximum time difference (in seconds) + when those files are still considered fresh and useful returns True, when files can be used, or False, when they don't exists or they are too old ''' @@ -77,10 +89,13 @@ def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600): return False try: - f = open(timestamp_path) - timestamp = int(f.readline()) - f.close() - except: + _file = open(timestamp_path) + timestamp = int(_file.readline()) + _file .close() + except Exception as ex: + if logger: + logger.debug("check_temp_files(); error retrieving" + " timestamp_path:\n" + str(ex)) timestamp = 0 return False @@ -92,17 +107,25 @@ def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600): if __name__ == '__main__': print('Preparing cache ... ') - from .collect import * + from .collect import (prepare_search_dirs, parse_revdep_config, + collect_libraries_from_dir, collect_binaries_from_dir) + import logging - bin_dirs, lib_dirs = prepare_search_dirs() + bin_dirs, lib_dirs = prepare_search_dirs(logging, DEFAULTS) - masked_dirs, masked_files, ld = parse_revdep_config() + masked_dirs, masked_files, ld = parse_revdep_config("/etc/revdep-rebuild/") lib_dirs.update(ld) bin_dirs.update(ld) - masked_dirs = masked_dirs.update(['/lib/modules', '/lib32/modules', '/lib64/modules',]) + masked_dirs = masked_dirs.update([ + '/lib/modules', + '/lib32/modules', + '/lib64/modules' + ] + ) - libraries, la_libraries, libraries_links, symlink_pairs = collect_libraries_from_dir(lib_dirs, masked_dirs, logging) + 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(logger=logging, diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py index 8239feb..3aae709 100644 --- a/pym/gentoolkit/revdep_rebuild/collect.py +++ b/pym/gentoolkit/revdep_rebuild/collect.py @@ -10,7 +10,7 @@ import glob import stat import portage -from portage.output import bold, red, blue, yellow, green, nocolor +from portage.output import blue, yellow def parse_conf(conf_file, visited=None, logger=None): @@ -66,12 +66,13 @@ def prepare_search_dirs(logger, settings): lib_dirs = set(['/lib', '/usr/lib', ]) #try: - with open(os.path.join(portage.root, settings['DEFAULT_ENV_FILE']), 'r') as _file: + with open(os.path.join( + portage.root, settings['DEFAULT_ENV_FILE']), 'r') as _file: for line in _file: line = line.strip() - m = re.match("^export (ROOT)?PATH='([^']+)'", line) - if m is not None: - bin_dirs.update(set(m.group(2).split(':'))) + match = re.match("^export (ROOT)?PATH='([^']+)'", line) + if match is not None: + bin_dirs.update(set(match.group(2).split(':'))) #except EnvironmentError: #logger.debug(yellow('Could not open file %s' % f)) @@ -80,35 +81,34 @@ def prepare_search_dirs(logger, settings): def parse_revdep_config(revdep_confdir): - ''' Parses all files under /etc/revdep-rebuild/ and returns + ''' Parses all files under and returns tuple of: (masked_dirs, masked_files, search_dirs)''' search_dirs = set() masked_dirs = set() masked_files = set() - #TODO: remove hard-coded path for _file in os.listdir(revdep_confdir): - for line in open(os.path.join('/etc/revdep-rebuild', _file)): + for line in open(os.path.join(revdep_confdir, _file)): line = line.strip() #first check for comment, we do not want to regex all lines if not line.startswith('#'): - m = re.match('LD_LIBRARY_MASK=\\"([^"]+)\\"', line) - if m is not None: - s = m.group(1).split(' ') - masked_files = masked_files.union(s) + match = re.match('LD_LIBRARY_MASK=\\"([^"]+)\\"', line) + if match is not None: + masks = match.group(1).split(' ') + masked_files = masked_files.union(masks) continue - m = re.match('SEARCH_DIRS_MASK=\\"([^"]+)\\"', line) - if m is not None: - s = m.group(1).split(' ') - for ss in s: - masked_dirs = masked_dirs.union(glob.glob(ss)) + match = re.match('SEARCH_DIRS_MASK=\\"([^"]+)\\"', line) + if match is not None: + searches = match.group(1).split(' ') + for search in searches: + masked_dirs = masked_dirs.union(glob.glob(search)) continue - m = re.match('SEARCH_DIRS=\\"([^"]+)\\"', line) - if m is not None: - s = m.group(1).split() - for ss in s: - search_dirs = search_dirs.union(glob.glob(ss)) + match = re.match('SEARCH_DIRS=\\"([^"]+)\\"', line) + if match is not None: + searches = match.group(1).split() + for search in searches: + search_dirs = search_dirs.union(glob.glob(search)) continue return (masked_dirs, masked_files, search_dirs) @@ -129,54 +129,58 @@ def collect_libraries_from_dir(dirs, mask, logger): found_la_files = [] # la libraries symlink_pairs = [] # list of pairs symlink_id->library_id - for d in dirs: - if d in mask: + for _dir in dirs: + if _dir in mask: continue try: - for l in os.listdir(d): - l = os.path.join(d, l) - if l in mask: + for listing in os.listdir(_dir): + listing = os.path.join(_dir, listing) + if listing in mask: continue - if os.path.isdir(l): - if os.path.islink(l): + if os.path.isdir(listing): + if os.path.islink(listing): #we do not want scan symlink-directories pass else: - found_directories.append(l) - elif os.path.isfile(l): - if l.endswith('.so') or l.endswith('.a') or '.so.' in l: - if l in found_files or l in found_symlinks: + found_directories.append(listing) + elif os.path.isfile(listing): + if (listing.endswith('.so') or + listing.endswith('.a') or + '.so.' in listing + ): + if listing in found_files or listing in found_symlinks: continue - if os.path.islink(l): - found_symlinks.append(l) - abs_path = os.path.realpath(l) + if os.path.islink(listing): + found_symlinks.append(listing) + abs_path = os.path.realpath(listing) if abs_path in found_files: - i = found_files.index(abs_path) + index = found_files.index(abs_path) else: found_files.append(abs_path) - i = len(found_files)-1 - symlink_pairs.append((len(found_symlinks)-1, i,)) + index = len(found_files)-1 + symlink_pairs.append((len(found_symlinks)-1, index,)) else: - found_files.append(l) + found_files.append(listing) continue - elif l.endswith('.la'): - if l in found_la_files: + elif listing.endswith('.la'): + if listing in found_la_files: continue - found_la_files.append(l) + found_la_files.append(listing) else: - # sometimes there are binaries in libs' subdir, for example in nagios - if not os.path.islink(l): - if l in found_files or l in found_symlinks: + # sometimes there are binaries in libs' subdir, + # for example in nagios + if not os.path.islink(listing): + if listing in found_files or listing in found_symlinks: continue - prv = os.stat(l)[stat.ST_MODE] + prv = os.stat(listing)[stat.ST_MODE] if prv & stat.S_IXUSR == stat.S_IXUSR or \ prv & stat.S_IXGRP == stat.S_IXGRP or \ prv & stat.S_IXOTH == stat.S_IXOTH: - found_files.append(l) + found_files.append(listing) except Exception as ex: logger.debug( yellow('Exception during collecting libraries: ' + @@ -184,18 +188,20 @@ def collect_libraries_from_dir(dirs, mask, logger): if found_directories: - f, a, l, p = collect_libraries_from_dir(found_directories, mask, logger) - found_files += f - found_la_files += a - found_symlinks += l - symlink_pairs += p + _file, la_file, link, pair = \ + collect_libraries_from_dir(found_directories, mask, logger) + found_files += _file + found_la_files += la_file + found_symlinks += link + symlink_pairs += pair return (found_files, found_la_files, found_symlinks, symlink_pairs) 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 + mask is list of pathes, that are ommited in scanning, + can be eighter single file or entire directory Returns list of binaries ''' @@ -204,36 +210,36 @@ def collect_binaries_from_dir(dirs, mask, logger): found_directories = [] found_files = [] - for d in dirs: - if d in mask: + for _dir in dirs: + if _dir in mask: continue try: - for l in os.listdir(d): - l = os.path.join(d, l) - if d in mask: + for listing in os.listdir(_dir): + listing = os.path.join(_dir, listing) + if listing in mask: continue - if os.path.isdir(l): - if os.path.islink(l): + if os.path.isdir(listing): + if os.path.islink(listing): #we do not want scan symlink-directories pass else: - found_directories.append(l) - elif os.path.isfile(l): + found_directories.append(listing) + elif os.path.isfile(listing): # we're looking for binaries # and with binaries we do not need links # thus we can optimize a bit - if not os.path.islink(l): - prv = os.stat(l)[stat.ST_MODE] + if not os.path.islink(listing): + prv = os.stat(listing)[stat.ST_MODE] if prv & stat.S_IXUSR == stat.S_IXUSR or \ prv & stat.S_IXGRP == stat.S_IXGRP or \ prv & stat.S_IXOTH == stat.S_IXOTH: - found_files.append(l) - except Exception as e: + found_files.append(listing) + except Exception as ex: logger.debug( yellow('Exception during binaries collecting: '+ - blue('%s') %str(e))) + blue('%s') %str(ex))) if found_directories: found_files += collect_binaries_from_dir(found_directories, mask, logger) @@ -244,15 +250,16 @@ def collect_binaries_from_dir(dirs, mask, logger): if __name__ == '__main__': import logging - mbin_dirs, mlib_dirs = prepare_search_dirs(logging) + from .settings import DEFAULTS + mbin_dirs, mlib_dirs = prepare_search_dirs(logging, DEFAULTS) - mmasked_dirs, mmasked_files, mld = parse_revdep_config() + mmasked_dirs, mmasked_files, mld = parse_revdep_config("/etc/revdep-rebuild/") mlib_dirs.update(mld) mbin_dirs.update(mld) mmasked_dirs.update(['/lib/modules', '/lib32/modules', '/lib64/modules']) - libraries, la_libraries, libraries_links, msymlink_pairs = collect_libraries_from_dir( - mlib_dirs, mmasked_dirs, logging) + libraries, la_libraries, libraries_links, msymlink_pairs = \ + collect_libraries_from_dir(mlib_dirs, mmasked_dirs, logging) binaries = collect_binaries_from_dir(mbin_dirs, mmasked_dirs, logging) logging.debug( diff --git a/pym/gentoolkit/revdep_rebuild/rebuild.py b/pym/gentoolkit/revdep_rebuild/rebuild.py index b529f37..5f64473 100644 --- a/pym/gentoolkit/revdep_rebuild/rebuild.py +++ b/pym/gentoolkit/revdep_rebuild/rebuild.py @@ -16,7 +16,6 @@ License: BSD from __future__ import print_function -import subprocess import os import sys import getopt @@ -24,7 +23,7 @@ import logging from portage.output import bold, red, blue, yellow, green, nocolor from .analyse import analyse -from .stuff import exithandler, get_masking_status +from .stuff import get_masking_status from .cache import check_temp_files, read_cache from .assign import get_slotted_cps from .settings import DEFAULTS @@ -208,7 +207,7 @@ def main(settings=None, logger=None): 'installed as revdep-rebuild.sh')) if settings['USE_TMP_FILES'] \ - and check_temp_files(settings['DEFAULT_TMP_DIR']): + and check_temp_files(settings['DEFAULT_TMP_DIR'], logger=logger): libraries, la_libraries, libraries_links, binaries = read_cache( settings['DEFAULT_TMP_DIR']) assigned = analyse( diff --git a/pym/gentoolkit/revdep_rebuild/stuff.py b/pym/gentoolkit/revdep_rebuild/stuff.py index bffb936..43be461 100644 --- a/pym/gentoolkit/revdep_rebuild/stuff.py +++ b/pym/gentoolkit/revdep_rebuild/stuff.py @@ -12,7 +12,12 @@ import portage # util. functions def call_program(args): - ''' Calls program with specified parameters and returns stdout as a str object ''' + ''' Calls program with specified parameters + and returns the stdout as a str object. + + @param, args: arument list to pass to subprocess + @return str + ''' subp = subprocess.Popen(args, stdout=subprocess.PIPE, \ stderr=subprocess.PIPE) stdout, stderr = subp.communicate() @@ -21,7 +26,8 @@ def call_program(args): def scan(params, files, max_args): ''' Calls scanelf with given params and files to scan. - @param params is list of parameters that should be passed into scanelf app. + @param params is list of parameters that should + be passed into scanelf app. @param files list of files to scan. @param max_args number of files to process at once @@ -56,9 +62,9 @@ def _match_str_in_list(lst, stri): @param stri: string @return boolean or list menber that matches stri.endswith(member) """ - for l in lst: - if stri.endswith(l): - return l + for item in lst: + if stri.endswith(item): + return item return False