[csw-devel] SF.net SVN: gar:[8570] csw/mgar/gar/v2-checkpkg-stats

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Feb 16 06:46:13 CET 2010


Revision: 8570
          http://gar.svn.sourceforge.net/gar/?rev=8570&view=rev
Author:   wahwah
Date:     2010-02-16 05:46:13 +0000 (Tue, 16 Feb 2010)

Log Message:
-----------
mGAR v2-checkpkg-stats: Collecting /usr/ccs/bin/dump info

Modified Paths:
--------------
    csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-libs.py
    csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg_collect_stats.py
    csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py
    csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py

Modified: csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-libs.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-libs.py	2010-02-16 03:36:57 UTC (rev 8569)
+++ csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg.d/checkpkg-libs.py	2010-02-16 05:46:13 UTC (rev 8570)
@@ -28,19 +28,6 @@
 import checkpkg
 import opencsw
 
-DUMP_BIN = "/usr/ccs/bin/dump"
-
-def GetIsalist():
-  args = ["isalist"]
-  isalist_proc = subprocess.Popen(args, stdout=subprocess.PIPE)
-  stdout, stderr = isalist_proc.communicate()
-  ret = isalist_proc.wait()
-  if ret:
-    logging.error("Calling isalist has failed.")
-  isalist = re.split(r"\s+", stdout.strip())
-  return isalist
-
-
 def CheckSharedLibraryConsistency(pkgs, debug):
   result_ok = True
   errors = []
@@ -48,9 +35,11 @@
   binaries_by_pkgname = {}
   sonames_by_pkgname = {}
   pkg_by_any_filename = {}
+  def MakeBinPathAbsolute(x):
+    return os.path.join(checker.directory, "root", x)
   for checker in pkgs:
-    pkg_binary_paths = checker.ListBinaries()
-    binaries_base = [os.path.split(x)[1] for x in pkg_binary_paths]
+    pkg_binary_paths = [MakeBinPathAbsolute(x) for x in checker.ListBinaries()]
+    binaries_base = [os.path.basename(x) for x in checker.ListBinaries()]
     binaries_by_pkgname[checker.pkgname] = binaries_base
     binaries.extend(pkg_binary_paths)
     for filename in checker.GetAllFilenames():
@@ -72,9 +61,11 @@
   #   ...
   # }
   #
+  # This bit to be replaced.
   for binary in binaries:
-    binary_base_name = binary.split("/")[-1]
-    args = [DUMP_BIN, "-Lv", binary]
+    # binary_base_name = binary.split("/")[-1]
+    binary_base_name = os.path.basename(binary)
+    args = [checkpkg.DUMP_BIN, "-Lv", binary]
     dump_proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=env)
     stdout, stderr = dump_proc.communicate()
     ret = dump_proc.wait()
@@ -89,7 +80,7 @@
       binary_data[checkpkg.SONAME] = binary_base_name
     filenames_by_soname[binary_data[checkpkg.SONAME]] = binary_base_name
 
-  isalist = GetIsalist()
+  isalist = checkpkg.GetIsalist()
 
   # Building indexes by soname to simplify further processing
   # These are indexes "by soname".

Modified: csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg_collect_stats.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg_collect_stats.py	2010-02-16 03:36:57 UTC (rev 8569)
+++ csw/mgar/gar/v2-checkpkg-stats/bin/checkpkg_collect_stats.py	2010-02-16 05:46:13 UTC (rev 8570)
@@ -5,12 +5,14 @@
 # Collects statistics about a package and saves to a directory, for later use
 # by checkpkg modules.
 
+import copy
 import errno
+import logging
+import optparse
 import os
 import os.path
+import subprocess
 import sys
-import logging
-import optparse
 import yaml
 
 # The following bit of code sets the correct path to Python libraries
@@ -86,15 +88,48 @@
       else:
       	raise
 
-  def CollectStats(self):
-    stats_path = self.GetStatsPath()
-    self.MakeStatsDir()
+  def GetBinaryDumpInfo(self):
     dir_pkg = self.GetDirFormatPkg()
-    self.DumpObject(dir_pkg.GetParsedPkginfo(), "pkginfo")
-    self.DumpObject(dir_pkg.GetPkgmap().entries, "pkgmap")
-    self.DumpObject(dir_pkg.ListBinaries(), "binaries")
-    self.DumpObject(dir_pkg.GetDependencies(), "depends")
-    self.DumpObject(dir_pkg.GetAllFilenames(), "all_filenames")
+    # Binaries. This could be split off to a separate function.
+    # man ld.so.1 for more info on this hack
+    env = copy.copy(os.environ)
+    env["LD_NOAUXFLTR"] = "1"
+    binaries_dump_info = []
+    for binary in dir_pkg.ListBinaries():
+      binary_abs_path = os.path.join(dir_pkg.directory, "root", binary)
+      binary_base_name = os.path.basename(binary)
+      args = [checkpkg.DUMP_BIN, "-Lv", binary_abs_path]
+      dump_proc = subprocess.Popen(args, stdout=subprocess.PIPE, env=env)
+      stdout, stderr = dump_proc.communicate()
+      ret = dump_proc.wait()
+      binary_data = checkpkg.ParseDumpOutput(stdout)
+      binary_data["path"] = binary
+      binary_data["soname_guessed"] = False
+      binary_data["base_name"] = binary_base_name
+      if checkpkg.SONAME not in binary_data:
+        logging.debug("The %s binary doesn't provide a SONAME. "
+                      "(It might be an executable)",
+                     binary_base_name)
+        # The binary doesn't tell its SONAME.  We're guessing it's the
+        # same as the base file name.
+        binary_data[checkpkg.SONAME] = binary_base_name
+        binary_data["soname_guessed"] = True
+      binaries_dump_info.append(binary_data)
+    return binaries_dump_info
+
+  def GetBasicStats(self):
+    dir_pkg = self.GetDirFormatPkg()
+    basic_stats = {}
+    basic_stats["stats_version"] = STATS_VERSION
+    basic_stats["pkg_path"] = self.srv4_pkg.pkg_path
+    basic_stats["pkg_basename"] = os.path.basename(self.srv4_pkg.pkg_path)
+    basic_stats["parsed_basename"] = opencsw.ParsePackageFileName(basic_stats["pkg_basename"])
+    basic_stats["pkgname"] = dir_pkg.pkgname
+    basic_stats["catalogname"] = dir_pkg.GetCatalogname()
+    return basic_stats
+
+  def GetOverrides(self):
+    dir_pkg = self.GetDirFormatPkg()
     overrides = dir_pkg.GetOverrides()
     def OverrideToDict(override):
       d = {}
@@ -103,16 +138,22 @@
       d["tag_info"] = override.tag_info
       return d
     overrides_simple = [OverrideToDict(x) for x in overrides]
-    self.DumpObject(overrides_simple, "overrides")
-    basic_stats = {}
-    basic_stats["stats_version"] = STATS_VERSION
-    basic_stats["pkg_path"] = self.srv4_pkg.pkg_path
-    basic_stats["pkg_basename"] = os.path.basename(self.srv4_pkg.pkg_path)
-    basic_stats["parsed_basename"] = opencsw.ParsePackageFileName(basic_stats["pkg_basename"])
-    basic_stats["pkgname"] = dir_pkg.pkgname
-    basic_stats["catalogname"] = dir_pkg.GetCatalogname()
-    self.DumpObject(basic_stats, "basic_stats")
+    return overrides_simple
 
+  def CollectStats(self):
+    stats_path = self.GetStatsPath()
+    self.MakeStatsDir()
+    dir_pkg = self.GetDirFormatPkg()
+    self.DumpObject(dir_pkg.GetParsedPkginfo(), "pkginfo")
+    self.DumpObject(dir_pkg.GetPkgmap().entries, "pkgmap")
+    self.DumpObject(dir_pkg.ListBinaries(), "binaries")
+    self.DumpObject(dir_pkg.GetDependencies(), "depends")
+    self.DumpObject(dir_pkg.GetAllFilenames(), "all_filenames")
+    self.DumpObject(checkpkg.GetIsalist(), "isalist")
+    self.DumpObject(self.GetOverrides, "overrides")
+    self.DumpObject(self.GetBasicStats(), "basic_stats")
+    self.DumpObject(self.GetBinaryDumpInfo(), "binaries_dump_info")
+
   def DumpObject(self, obj, name):
     stats_path = self.GetStatsPath()
     out_file_name = os.path.join(self.GetStatsPath(), "%s.yml" % name)

Modified: csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py	2010-02-16 03:36:57 UTC (rev 8569)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/checkpkg.py	2010-02-16 05:46:13 UTC (rev 8570)
@@ -24,6 +24,7 @@
 DO_NOT_REPORT_SURPLUS = set([u"CSWcommon", u"CSWcswclassutils", u"CSWisaexec"])
 DO_NOT_REPORT_MISSING = set([])
 DO_NOT_REPORT_MISSING_RE = [r"SUNW.*", r"\*SUNW.*"]
+DUMP_BIN = "/usr/ccs/bin/dump"
 
 SYSTEM_SYMLINKS = (
     ("/opt/csw/bdb4", ["/opt/csw/bdb42"]),
@@ -714,3 +715,14 @@
     if not override_applies:
       tags_after_overrides.append(tag)
   return tags_after_overrides
+
+
+def GetIsalist():
+  args = ["isalist"]
+  isalist_proc = subprocess.Popen(args, stdout=subprocess.PIPE)
+  stdout, stderr = isalist_proc.communicate()
+  ret = isalist_proc.wait()
+  if ret:
+    logging.error("Calling isalist has failed.")
+  isalist = re.split(r"\s+", stdout.strip())
+  return isalist

Modified: csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py	2010-02-16 03:36:57 UTC (rev 8569)
+++ csw/mgar/gar/v2-checkpkg-stats/lib/python/opencsw.py	2010-02-16 05:46:13 UTC (rev 8570)
@@ -574,6 +574,7 @@
     self.pkgname = os.path.split(directory)[1]
     self.pkgpath = self.directory
     self.pkginfo_dict = None
+    self.binaries = None
 
   def GetCatalogname(self):
     """Returns the catalog name of the package.
@@ -713,16 +714,23 @@
 
     Returns a list of absolute paths.
     """
-    self.CheckPkgpathExists()
-    find_tmpl = "find '%s' -print | xargs file | grep ELF | nawk -F: '{print $1}'"
-    find_proc = subprocess.Popen(find_tmpl % self.directory,
-                                 shell=True,
-                                 stdout=subprocess.PIPE)
-    stdout, stderr = find_proc.communicate()
-    ret = find_proc.wait()
-    if ret:
-      logging.error("The find command returned an error.")
-    return stdout.splitlines()
+    if not self.binaries:
+      self.CheckPkgpathExists()
+      files_root = os.path.join(self.directory, "root")
+      find_tmpl = "find '%s' -print | xargs file | grep ELF | nawk -F: '{print $1}'"
+      find_proc = subprocess.Popen(find_tmpl % ".",
+                                   shell=True,
+                                   stdout=subprocess.PIPE,
+                                   cwd=files_root)
+      stdout, stderr = find_proc.communicate()
+      ret = find_proc.wait()
+      if ret:
+        logging.error("The find command returned an error.")
+      dotslash_re = re.compile(r"^./")
+      def StripRe(x, strip_re):
+        return re.sub(strip_re, "", x)
+      self.binaries = [StripRe(x, dotslash_re) for x in stdout.splitlines()]
+    return self.binaries
 
   def GetAllFilenames(self):
     self.CheckPkgpathExists()


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list