Revision: 19276 http://gar.svn.sourceforge.net/gar/?rev=19276&view=rev Author: chninkel Date: 2012-09-22 16:15:20 +0000 (Sat, 22 Sep 2012) Log Message: ----------- pep8 compliance fixes
Modified Paths: -------------- csw/mgar/gar/v2-yann/lib/python/dependency_checks.py csw/mgar/gar/v2-yann/lib/python/inspective_package.py Modified: csw/mgar/gar/v2-yann/lib/python/dependency_checks.py =================================================================== --- csw/mgar/gar/v2-yann/lib/python/dependency_checks.py 2012-09-22 13:46:13 UTC (rev 19275) +++ csw/mgar/gar/v2-yann/lib/python/dependency_checks.py 2012-09-22 16:15:20 UTC (rev 19276) @@ -29,10 +29,11 @@ ) DEPENDENCY_FILENAME_REGEXES = ( - (r".*\.pl$", (u"CSWperl",)), - (r".*\.pm$", (u"CSWperl",)), - (r".*\.py$", (u"CSWpython",)), - (r".*\.rb$", (u"CSWruby", u"CSWruby18", u"CSWruby191", u"CSWlibruby1-9-1-1")), + (r".*\.pl$", (u"CSWperl",)), + (r".*\.pm$", (u"CSWperl",)), + (r".*\.py$", (u"CSWpython",)), + (r".*\.rb$", (u"CSWruby", u"CSWruby18", + u"CSWruby191", u"CSWlibruby1-9-1-1")), (r".*\.elc?$", (u"CSWemacscommon",)), (r"/opt/csw/apache2/", (u"CSWapache2",)), ) @@ -40,9 +41,12 @@ PREFERRED_DIRECTORY_PROVIDERS = set([u"CSWcommon"]) BASE_SOLARIS_LIBRARIES = ( - "libsocket.so.1", "libnsl.so.1", "libdl.so.1", "librt.so.1", "libresolv.so.2", "libpthread.so.1", - # linked by default with C++, see "Default C++ Libraries" in Solaris Studio C++ User'sGuide - "libCstd.so.1", "libCrun.so.1", "libm.so.1", "libm.so.2", "libw.so.1", "libcx.so.1", "libc.so.1", "libC.so.3", "libC.so.5", + "libsocket.so.1", "libnsl.so.1", "libdl.so.1", "librt.so.1", + "libresolv.so.2", "libpthread.so.1", + # linked by default with C++, see "Default C++ Libraries" + # in Solaris Studio C++ User's Guide + "libCstd.so.1", "libCrun.so.1", "libm.so.1", "libm.so.2", + "libw.so.1", "libcx.so.1", "libc.so.1", "libC.so.3", "libC.so.5", ) ALLOWED_VERSION_DEPENDENCIES = { @@ -61,8 +65,8 @@ def ProcessSoname( ldd_emulator, - soname, path_and_pkg_by_basename, binary_info, isalist, binary_path, logger, - error_mgr, + soname, path_and_pkg_by_basename, binary_info, isalist, binary_path, + logger, error_mgr, pkgname, messenger): """This is not an ideal name for this function. @@ -163,59 +167,69 @@ for soname in binary_info["needed sonames"]: orphan_sonames_tmp = ProcessSoname( ldd_emulator, - soname, path_and_pkg_by_basename, binary_info, isalist, binary_path, logger, - error_mgr, + soname, path_and_pkg_by_basename, binary_info, isalist, binary_path, + logger, error_mgr, pkgname, messenger) orphan_sonames.extend(orphan_sonames_tmp) ldd_info = pkg_data['ldd_info'][binary_info["path"]] for ldd_response in ldd_info: - if ldd_response['state'] == 'soname-unused' and ldd_response['soname'] not in BASE_SOLARIS_LIBRARIES: + if (ldd_response['state'] == 'soname-unused' + and ldd_response['soname'] not in BASE_SOLARIS_LIBRARIES): messenger.Message( - "Binary %s links to library %s but doesn't seem to use any of its symbols. " - "It usually happens because superfluous libraries were added to the linker options, " - "either because of the configure script itself or because of the \"pkg-config --libs\"" - " output of one the dependency." + "Binary %s links to library %s but doesn't seem to use any" + " of its symbols. It usually happens because superfluous" + " libraries were added to the linker options, either because" + " of the configure script itself or because of the" + " \"pkg-config --libs\" output of one the dependency." % ("/" + binary_info["path"], ldd_response['soname'])) error_mgr.ReportError( pkgname, "soname-unused", - "%s is needed by %s but never used" % (ldd_response['soname'], "/" + binary_info["path"])) + "%s is needed by %s but never used" + % (ldd_response['soname'], "/" + binary_info["path"])) # Even when direct binding is enabled, some symbols might not be # directly bound because the library explicitely requested the symbol # not to be drectly bound to. - # For example, libc.so.1 does it for symbol sigaction, free, malloc and realloc - # So we consider that direct binding is enabled if at least one symbol is directly - # bound to because that definitely means that -B direct or -z direct was used. - directly_bound = set() - for syminfo in pkg_data["binaries_elf_info"][binary_info["path"]]['symbol table']: + # For example, libc.so.1 does it for symbol sigaction, free, malloc... + # So we consider that direct binding is enabled if at least one + # symbol is directly bound to because that definitely means that + # -B direct or -z direct was used. + binary_elf_info = pkg_data["binaries_elf_info"][binary_info["path"]] + db_libs = set() + for syminfo in binary_elf_info['symbol table']: if (syminfo['shndx'] == 'UNDEF' and syminfo['flags'] and 'D' in syminfo['flags'] and 'B' in syminfo['flags']): - directly_bound.add(syminfo['soname']) - not_directly_bound = directly_bound.symmetric_difference(binary_info["needed sonames"]) + db_libs.add(syminfo['soname']) + no_db_libs = db_libs.symmetric_difference(binary_info["needed sonames"]) - if not_directly_bound: + if no_db_libs: messenger.Message( - "No symbol of binary %s is directly bound against the following libraries: %s. " - "Please make sure the binaries are compiled using the \"-Bdirect\" linker option." - % ("/" + binary_info["path"], ", ".join(not_directly_bound))) - for soname in not_directly_bound: + "No symbol of binary %s is directly bound against the following" + " libraries: %s. Please make sure the binaries are compiled using" + " the \"-Bdirect\" linker option." + % ("/" + binary_info["path"], ", ".join(no_db_libs))) + for soname in no_db_libs: error_mgr.ReportError( pkgname, "no-direct-binding", - "%s is not directly bound to soname %s" % ("/" + binary_info["path"], soname)) + "%s is not directly bound to soname %s" + % ("/" + binary_info["path"], soname)) - for version_dep in pkg_data["binaries_elf_info"][binary_info["path"]]['version needed']: + for version_dep in binary_elf_info['version needed']: if (version_dep['soname'] in ALLOWED_VERSION_DEPENDENCIES and - not version_dep['version'] in ALLOWED_VERSION_DEPENDENCIES[version_dep['soname']]): + not version_dep['version'] in + ALLOWED_VERSION_DEPENDENCIES[version_dep['soname']]): messenger.Message( - "Binary %s requires interface version %s in library %s which is only available " - "in recent Solaris releases." - % ("/" + binary_info["path"], version_dep['version'], version_dep['soname'])) + "Binary %s requires interface version %s in library %s which is" + " only available in recent Solaris releases." + % ("/" + binary_info["path"], version_dep['version'], + version_dep['soname'])) error_mgr.ReportError( pkgname, "forbidden-version-interface-dependencies", "%s requires forbidden interface version %s in library %s" - % ("/" + binary_info["path"], version_dep['version'], version_dep['soname'])) + % ("/" + binary_info["path"], version_dep['version'], + version_dep['soname'])) orphan_sonames = set(orphan_sonames) @@ -262,8 +276,8 @@ needed_dirs.add(base_dir) for needed_dir in needed_dirs: reason_group = [] - # TODO: The preferred directory providers should not depend on other packages to - # provide directories. + # TODO: The preferred directory providers should not depend on other + # packages to provide directories. if pkgname not in PREFERRED_DIRECTORY_PROVIDERS: # If the path is provided by CSWcommon or other preferred package, don't # mention other packages. @@ -277,7 +291,8 @@ if not pkg_by_path[needed_dir]: # There's no sense in reporting '/' and ''. if needed_dir and needed_dir != '/': - error_mgr.ReportError(pkgname, "base-dir-not-found", repr(needed_dir)) + error_mgr.ReportError(pkgname, "base-dir-not-found", + repr(needed_dir)) elif len(pkg_by_path[needed_dir]) < 5: pkgs_to_mention = pkg_by_path[needed_dir] else: @@ -289,7 +304,8 @@ if reason_group: req_pkgs_reasons.append(reason_group) else: - error_mgr.ReportError(pkgname, "base-dir-not-provided-by-any-package", needed_dir) + error_mgr.ReportError(pkgname, "base-dir-not-provided-by-any-package", + needed_dir) return req_pkgs_reasons @@ -303,6 +319,7 @@ error_mgr.GetPathsAndPkgnamesByBasename(basename)) return path_and_pkg_by_basename + def GetPkgByFullPath(error_mgr, logger, paths_to_verify, pkg_by_path): """Resolves a list of paths to a mapping between paths and packages. @@ -313,11 +330,13 @@ for path in paths_to_verify: if path not in pkg_by_path: result = error_mgr.GetPkgByPath(path) - # logger.warning("error_mgr.GetPkgByPath(%s) => %s", repr(path), repr(result)) + # logger.warning("error_mgr.GetPkgByPath(%s) => %s", repr(path), + # repr(result)) pkg_by_path[path] = result # logger.warning("New paths: %s" % pprint.pformat(pkg_by_path)) return pkg_by_path + def SuggestLibraryPackage(error_mgr, messenger, pkgname, catalogname, description, Modified: csw/mgar/gar/v2-yann/lib/python/inspective_package.py =================================================================== --- csw/mgar/gar/v2-yann/lib/python/inspective_package.py 2012-09-22 13:46:13 UTC (rev 19275) +++ csw/mgar/gar/v2-yann/lib/python/inspective_package.py 2012-09-22 16:15:20 UTC (rev 19276) @@ -35,7 +35,7 @@ return {} file_info = { "path": StripRe(file_path, ROOT_RE), - "mime_type": file_magic.GetFileMimeType(full_path) + "mime_type": file_magic.GetFileMimeType(full_path), } if base_dir: file_info["path"] = os.path.join(base_dir, file_info["path"]) @@ -69,16 +69,17 @@ "Error in hachoir_parser processing %s: %r", file_path, e) return file_info + def ShellCommand(args, env=None): - logging.debug("Running: %s", args) - proc = subprocess.Popen(args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=env) - stdout, stderr = proc.communicate() - retcode = proc.wait() + logging.debug("Running: %s", args) + proc = subprocess.Popen(args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env) + stdout, stderr = proc.communicate() + retcode = proc.wait() - return retcode, stdout, stderr + return retcode, stdout, stderr class InspectivePackage(package.DirectoryFormatPackage): @@ -164,7 +165,8 @@ return os.path.exists(os.path.join(self.directory, "reloc")) def GetFilesDir(self): - """Returns the subdirectory in which files, are either "reloc" or "root".""" + """Returns the subdirectory in which files are, + either "reloc" or "root".""" if self.RelocPresent(): return "reloc" else: @@ -185,9 +187,11 @@ if basedir: binary_in_tmp_dir = binary_in_tmp_dir[len(basedir):] binary_in_tmp_dir = binary_in_tmp_dir.lstrip("/") - binary_abs_path = os.path.join(self.directory, self.GetFilesDir(), binary_in_tmp_dir) + binary_abs_path = os.path.join(self.directory, self.GetFilesDir(), + binary_in_tmp_dir) binary_base_name = os.path.basename(binary_in_tmp_dir) - retcode, stdout, stderr = ShellCommand([common_constants.DUMP_BIN, "-Lv", binary_abs_path], env) + args = [common_constants.DUMP_BIN, "-Lv", binary_abs_path] + retcode, stdout, stderr = ShellCommand(args, env) binary_data = ldd_emul.ParseDumpOutput(stdout) binary_data["path"] = binary if basedir: @@ -240,12 +244,14 @@ """Returns various informations symbol and versions present in elf header To do this we parse output lines from elfdump -syv, it's the - only command that will give us all informations we need on symbols and versions. + only command that will give us all informations we need on + symbols and versions. + We will analyse 3 sections: - - version section: contains soname needed, version interface required for each soname, - and version definition - - symbol table section: contains list of symbol and soname/version interface providing it - (the latter is an index in the version section) + - version section: contains soname needed, version interface required + for each soname, and version definition + - symbol table section: contains list of symbol and soname/version + interface providing it - syminfo section: contains special linking flags for each symbol """ binaries = self.ListBinaries() @@ -266,7 +272,8 @@ 'version needed': []} # The list of fields we want to retrieve in the elfdump output by section - # the key is the original field name and the value the destination field name + # the key is the original field name + # the value is the destination field name elf_fields = {'version definition': { 'version': 'version', 'dependency': 'dependency', @@ -323,9 +330,9 @@ binary_info['symbol table'] = symbols.values() binary_info['symbol table'].sort(key=lambda m: m['symbol']) - # To not rely of the section order output of elfdump, we resolve symbol version - # informations here after having parsed all elfdump output - self._ResolveSymbolsVersionInfo (binary_info) + # To not rely of the section order output of elfdump, we resolve + # symbol version informations here after having parsed all output + self._ResolveSymbolsVersionInfo(binary_info) binaries_elf_info[binary] = binary_info @@ -345,11 +352,13 @@ if retcode: uname_info = os.uname() if (uname_info[2] == '5.9' and uname_info[4] == 'i86pc' and - '/amd64/' in binary_abspath and 'has wrong class or data encoding' in stderr): + '/amd64/' in binary_abspath and + 'has wrong class or data encoding' in stderr): # we are trying to analyze a 64 bits binary on a Solaris 9 x86 # which exists only in 32 bits, that's not possible # we ignore the error and return no information as it is likely - # that the ldd infos will be the same on the 32 bits binaries analyzed + # that the ldd infos will be the same on the 32 bits binaries + # analyzed ldd_output[binary] = [] continue else: @@ -370,19 +379,21 @@ if not m: return None fields = line.split() - sym = { 'address': fields[0], 'type': fields[1], 'name': fields[2] } + sym = {'address': fields[0], 'type': fields[1], 'name': fields[2]} return sym def _ResolveSymbolsVersionInfo(self, binary_info): - version_info = binary_info['version definition'] + binary_info['version needed'] + version_info = (binary_info['version definition'] + + binary_info['version needed']) for sym_info in binary_info['symbol table']: - # sym_info version field is an 1-based index on the version information table + # sym_info version field is an 1-based index on the version + # information table # we don't care about 0 and 1 values: # 0 is for external symbol with no version information available - # 1 is for a symbol defined by the binary and not binded to a version interface - # but we removed that (useless) entry from the version definition table + # 1 is for a symbol defined by the binary and not binded + # to a version interface version_index = int(sym_info['version']) - 2 if version_index >= 0: version = version_info[version_index] @@ -392,27 +403,32 @@ else: sym_info['version'] = None - # we make sure these fields are present even if the syminfo section is not + # we make sure these fields are present + # even if the syminfo section is not sym_info.setdefault('soname') sym_info.setdefault('flags') - def _ParseElfdumpLine(self, line, section=None): headers_re = ( r""" - (?P<section>Version\sNeeded|Symbol\sTable # Section header + (?P<section>Version\sNeeded|Symbol\sTable # Section header |Version\sDefinition|Syminfo) \sSection: \s+(?:\.SUNW_version|\.dynsym |\.SUNW_syminfo|.symtab)\s*$ - |\s*(?:index\s+)?version\s+dependency\s*$ # Version needed header - |\s*(?:index\s+)?file\s+version\s*$ # Version definition header - |\s*index\s*value\s+size\s+type\s+bind # Symbol table header + + |\s*(?:index\s+)?version\s+dependency\s*$ # Version needed header + + |\s*(?:index\s+)?file\s+version\s*$ # Version definition header + + |\s*index\s*value\s+size\s+type\s+bind # Symbol table header \s+oth\s+ver\s+shndx\s+name\s*$ - |\s*index\s+flags\s+bound\sto\s+symbol\s*$ # Syminfo header - |\s*$ # There is always a blank - # line before a new section + + |\s*index\s+flags\s+bound\sto\s+symbol\s*$ # Syminfo header + + |\s*$ # There is always a blank + # line before a new section """) re_by_section = { @@ -483,17 +499,22 @@ r'with STV_PROTECTED visibility$') sizes_differ = (r'^\trelocation \S+ sizes differ: ' r'(?P<sizes_differ_symbol>\S+)$') - sizes_info = (r'^\t\t\(file (?P<sizediff_file1>\S+) size=(?P<size1>0x\w+); ' + sizes_info = (r'^\t\t\(file (?P<sizediff_file1>\S+)' + ' size=(?P<size1>0x\w+); ' r'file (?P<sizediff_file2>\S+) size=(?P<size2>0x\w+)\)$') sizes_one_used = (r'^\t\t(?P<sizediffused_file>\S+) size used; ' r'possible insufficient data copied$') - unreferenced_object = (r'^\s*unreferenced object=(?P<object>.*); unused dependency of (?P<binary>.*)$') + unreferenced_object = (r'^\s*unreferenced object=(?P<object>.*);' + ' unused dependency of (?P<binary>.*)$') unused_object = (r'^\s*unused object=.*$') - unused_search_path = (r'^\s*unused search path=.* \(RUNPATH/RPATH from file .*\)$') + unused_search_path = (r'^\s*unused search path=.*' + ' \(RUNPATH/RPATH from file .*\)$') blank_line = (r'^\s*$') common_re = (r"(%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s)" - % (found_re, symbol_not_found_re, only_so, version_so, stv_protected, sizes_differ, sizes_info, - sizes_one_used, unreferenced_object, unused_object, unused_search_path, blank_line)) + % (found_re, symbol_not_found_re, only_so, version_so, + stv_protected, sizes_differ, sizes_info, + sizes_one_used, unreferenced_object, unused_object, + unused_search_path, blank_line)) m = re.match(common_re, line) response = None if m: @@ -526,7 +547,8 @@ response["path"] = None response["symbol"] = None elif d["relocation_symbol"]: - response["state"] = 'relocation-bound-to-a-symbol-with-STV_PROTECTED-visibility' + response["state"] = ("relocation-bound-to-a-symbol" + "-with-STV_PROTECTED-visibility") response["soname"] = None response["path"] = d["relocation_path"] response["symbol"] = d["relocation_symbol"] @@ -618,9 +640,9 @@ pkgname, catalogname = fields[0:2] obsoleted_by.append((pkgname, catalogname)) - return { "syntax_ok": obsoleted_syntax_ok, - "obsoleted_by": obsoleted_by, - "has_obsolete_info": has_obsolete_info } + return {"syntax_ok": obsoleted_syntax_ok, + "obsoleted_by": obsoleted_by, + "has_obsolete_info": has_obsolete_info} class FileMagic(object): @@ -655,7 +677,7 @@ for i in xrange(10): mime = self.magic_cookie.file(full_path) if mime: - break; + break else: # Returned mime is null. Re-initializing the cookie and trying again. logging.error("magic_cookie.file(%s) returned None. Retrying.", @@ -675,6 +697,7 @@ # The presence of this method makes it explicit that we want an inspective # version of the directory format package. + def GetInspectivePkg(self): return self.GetDirFormatPkg() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ devel mailing list devel@lists.opencsw.org https://lists.opencsw.org/mailman/listinfo/devel