From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id EB125138D03 for ; Wed, 12 Feb 2014 10:22:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A5B51E0D66; Wed, 12 Feb 2014 10:22:10 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B885FE0D65 for ; Wed, 12 Feb 2014 10:22:09 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BA7A333FA14 for ; Wed, 12 Feb 2014 10:22:08 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 4719918873 for ; Wed, 12 Feb 2014 10:22:07 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1392199611.da09ff6866ac6a7425996af920d716d8e2ce5d0b.dol-sen@gentoo> Subject: [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/revdep_rebuild/ X-VCS-Repository: proj/gentoolkit X-VCS-Files: pym/gentoolkit/revdep_rebuild/analyse.py X-VCS-Directories: pym/gentoolkit/revdep_rebuild/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: da09ff6866ac6a7425996af920d716d8e2ce5d0b X-VCS-Branch: gentoolkit Date: Wed, 12 Feb 2014 10:22:07 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 0460f0d4-7dd3-4be4-8c75-dd3a4e384044 X-Archives-Hash: a619ee601c35af7668fea74ef82ddc7f commit: da09ff6866ac6a7425996af920d716d8e2ce5d0b Author: Brian Dolbec gentoo org> AuthorDate: Wed Feb 12 10:06:51 2014 +0000 Commit: Brian Dolbec gmail com> CommitDate: Wed Feb 12 10:06:51 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=da09ff68 revdep_rebuild/analyse.py: Create LibCheck class for searching & processing the data. Move find_broken2() and main_checks2() into the new class. Rename them to search(), process_results() to better reflect their roles. Enable the class to do both broken libs searches and specified lib searches. --- pym/gentoolkit/revdep_rebuild/analyse.py | 128 ++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 28 deletions(-) diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py index fb75bc8..daeb4fc 100644 --- a/pym/gentoolkit/revdep_rebuild/analyse.py +++ b/pym/gentoolkit/revdep_rebuild/analyse.py @@ -92,34 +92,105 @@ def extract_dependencies_from_la(la, libraries, to_check, logger): return broken -def find_broken2(scanned_files, logger): - broken_libs = {} - for bits, libs in scanned_files.items(): - logger.debug('find_broken2(), Checking for %s bit libs' % bits) - alllibs = '|'.join(sorted(libs)) + '|' - for soname, filepaths in libs.items(): - for filename, needed in filepaths.items(): - for l in needed: - if l+'|' not in alllibs: - try: - broken_libs[bits][l].add(filename) - except KeyError: +class LibCheck(object): + def __init__(self, scanned_files, logger, searchlibs=None): + '''LibCheck init function. + + @param scanned_files: optional dictionary if the type created by + scan_files(). Defaults to the class instance of scanned_files + @param logger: python style Logging function to use for output. + @param searchlibs: optional set() of libraries to search for. If defined + it toggles several settings to configure this class for + a target search rather than a broken libs search. + ''' + self.scanned_files = scanned_files + self.logger = logger + self.searchlibs = searchlibs + if searchlibs: + self.smsg = '\tLibCheck.search(), Checking for %s bit dependants' + self.pmsg = yellow(" * ") + 'Files that depend on: %s (%s bits)' + self.alllibs = '|'.join(sorted(searchlibs)) + '|' + self.setlibs = self._lamda + self.check = self._checkforlib + else: + self.smsg = '\tLibCheck.search(), Checking for broken %s bit libs' + self.pmsg = green(' * ') + bold('Broken files that requires:') + ' %s (%s bits)' + self.setlibs = self._setlibs + self.check = self._checkbroken + self.alllibs = None + + + @staticmethod + def _lamda(l): + '''Internal function. Use the class's setlibs variable''' + pass + + + def _setlibs(self, l): + '''Internal function. Use the class's setlibs variable''' + self.alllibs = '|'.join(sorted(l)) + '|' + + + def _checkforlib(self, l): + '''Internal function. Use the class's check variable''' + if l: + return l+'|' in self.alllibs + return False + + + def _checkbroken(self, l): + '''Internal function. Use the class's check variable''' + if l: + return l+'|' not in self.alllibs + return False + + + def search(self, scanned_files=None): + '''Searches the scanned files for broken lib links + or for libs to search for + + @param scanned_files: optional dictionary if the type created by + scan_files(). Defaults to the class instance of scanned_files + @ returns: dict: {bit_length: {found_lib: set(file_paths)}}. + ''' + if not scanned_files: + scanned_files = self.scanned_files + found_libs = {} + for bits, libs in scanned_files.items(): + self.setlibs(libs) + self.logger.debug(self.smsg % bits) + for soname, filepaths in libs.items(): + for filename, needed in filepaths.items(): + for l in needed: + if self.check(l): try: - broken_libs[bits][l] = set([filename]) + found_libs[bits][l].add(filename) except KeyError: - broken_libs = {bits: {l: set([filename])}} - return broken_libs - - -def main_checks2(broken, scanned_files, logger): - broken_pathes = [] - for bits, _broken in broken.items(): - for lib, files in _broken.items(): - logger.info('Broken files that requires: %s (%s bits)' % (bold(lib), bits)) - for fp in sorted(files): - logger.info(yellow(' * ') + fp) - broken_pathes.append(fp) - return broken_pathes + try: + found_libs[bits][l] = set([filename]) + except KeyError: + found_libs = {bits: {l: set([filename])}} + return found_libs + + + def process_results(self, found_libs, scanned_files=None): + '''Processes the search results, logs the files found + + @param found_libs: dictionary of the type returned by search() + @param scanned_files: optional dictionary if the type created by + scan_files(). Defaults to the class instance of scanned_files + @ returns: list: of filepaths from teh search results. + ''' + if not scanned_files: + scanned_files = self.scanned_files + found_pathes = [] + for bits, found in found_libs.items(): + for lib, files in found.items(): + self.logger.info(self.pmsg % (bold(lib), bits)) + for fp in sorted(files): + self.logger.info('\t' +yellow('* ') + fp) + found_pathes.append(fp) + return found_pathes def analyse(settings, logger, libraries=None, la_libraries=None, @@ -187,8 +258,9 @@ def analyse(settings, logger, libraries=None, la_libraries=None, (len(libs_and_bins), len(libraries)+len(libraries_links)) ) - broken = find_broken2(scanned_files, logger) - broken_pathes = main_checks2(broken, scanned_files, logger) + libcheck = LibCheck(scanned_files, logger, _libs_to_check) + + broken_pathes = libcheck.process_results(libcheck.search()) broken_la = extract_dependencies_from_la(la_libraries, libraries+libraries_links, _libs_to_check, logger)