[csw-devel] SF.net SVN: gar:[8273] csw/mgar/gar/v2

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Jan 31 19:14:32 CET 2010


Revision: 8273
          http://gar.svn.sourceforge.net/gar/?rev=8273&view=rev
Author:   wahwah
Date:     2010-01-31 18:14:31 +0000 (Sun, 31 Jan 2010)

Log Message:
-----------
mGAR v2: Added missing symbols check, modified the output to be slightly nicer.

Modified Paths:
--------------
    csw/mgar/gar/v2/bin/checkpkg
    csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py
    csw/mgar/gar/v2/lib/python/checkpkg.py
    csw/mgar/gar/v2/lib/python/opencsw.py

Added Paths:
-----------
    csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-missing-symbols.py

Modified: csw/mgar/gar/v2/bin/checkpkg
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg	2010-01-31 17:45:49 UTC (rev 8272)
+++ csw/mgar/gar/v2/bin/checkpkg	2010-01-31 18:14:31 UTC (rev 8273)
@@ -36,10 +36,12 @@
 if [[ -t 1 ]]; then
 	GREEN="\\033[0;32;40m"
 	RED="\\033[1;31;40m"
+	BOLD="\\033[1m"
 	COLOR_RESET="\\033[00m"
 else
 	GREEN=""
 	RED=""
+	BOLD=""
 	COLOR_RESET=""
 fi
 
@@ -591,13 +593,14 @@
 			plugin_base_name=`basename ${plugin}`
 			plugin_log="${EXTRACTDIR}/${plugin_base_name}.log"
 			log_files="${log_files} ${plugin_log}"
-			printf "TEST: ${plugin} running..."
+			plugin_name="`echo ${plugin} | sed -e 's+.*/checkpkg-++' | sed -e 's+\.py$++'`"
+			printf "TEST: ${BOLD}${plugin_name}${COLOR_RESET} running..."
 			${plugin} $extra_options -e "${EXTRACTDIR}" ${pkgnames} > "${plugin_log}" 2>&1
 			if [[ "$?" -ne 0 ]]; then
-				printf "\rTEST: ${plugin} ${RED}[FAIL]${COLOR_RESET}        \\n"
+				printf "\rTEST: ${plugin_name} ${RED}[FAIL]${COLOR_RESET}        \\n"
 				test_suite_ok=0
 			else
-				printf "\rTEST: ${plugin} ${GREEN}[OK]${COLOR_RESET}        \\n"
+				printf "\rTEST: ${plugin_name} ${GREEN}[OK]${COLOR_RESET}        \\n"
 			fi
 		else
 			debugmsg "'${plugin}' is not executable"
@@ -607,7 +610,6 @@
 	debugmsg "plugin dir does not exist"
 fi
 
-echo
 for log_file in ${log_files}; do
 	if [[ -s "${log_file}" ]]; then
 		debugmsg ">> LOG START: ${log_file}"
@@ -617,7 +619,6 @@
   	debugmsg "-- LOG ${log_file} is empty"
 	fi
 done
-echo
 
 if [[ ${test_suite_ok} -ne 1 ]]; then
 	errmsg "One or more modular tests have failed."

Added: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-missing-symbols.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-missing-symbols.py	                        (rev 0)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-missing-symbols.py	2010-01-31 18:14:31 UTC (rev 8273)
@@ -0,0 +1,64 @@
+#!/opt/csw/bin/python2.6
+# $Id$
+
+"""Check for missing symbols in binaries.
+
+http://sourceforge.net/tracker/?func=detail&aid=2939416&group_id=229205&atid=1075770
+"""
+
+import os.path
+import re
+import sys
+import subprocess
+
+CHECKPKG_MODULE_NAME = "missing symbols"
+
+# The following bit of code sets the correct path to Python libraries
+# distributed with GAR.
+path_list = [os.path.dirname(__file__),
+             "..", "..", "lib", "python"]
+sys.path.append(os.path.join(*path_list))
+import checkpkg
+
+# Defining checking functions.
+
+def CheckForMissingSymbols(pkg):
+  """Looks for "symbol not found" in ldd -r output."""
+  errors = []
+  binaries = pkg.ListBinaries()
+  symbol_re = re.compile(r"symbol not found:")
+  for binary in binaries:
+    # this could be potentially moved into the DirectoryFormatPackage class.
+    args = ["ldd", "-r", binary]
+    ldd_proc = subprocess.Popen(
+        args,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE)
+    stdout, stderr = ldd_proc.communicate()
+    retcode = ldd_proc.wait()
+    lines = stdout.splitlines()
+    for line in lines:
+      if re.search(symbol_re, line):
+        errors.append(checkpkg.PackageError("%s: %s" % (pkg.pkgname, line)))
+  return errors
+
+
+def main():
+  options, args = checkpkg.GetOptions()
+  pkgnames = args
+  # CheckpkgManager class abstracts away things such as the collection of
+  # results.
+  check_manager = checkpkg.CheckpkgManager(CHECKPKG_MODULE_NAME,
+                                           options.extractdir,
+                                           pkgnames,
+                                           options.debug)
+  # Registering functions defined above.
+  check_manager.RegisterIndividualCheck(CheckForMissingSymbols)
+  # Running the checks, reporting and exiting.
+  exit_code, report = check_manager.Run()
+  print report.strip()
+  sys.exit(exit_code)
+
+
+if __name__ == '__main__':
+  main()


Property changes on: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-missing-symbols.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Id

Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py	2010-01-31 17:45:49 UTC (rev 8272)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-you-can-write-your-own.py	2010-01-31 18:14:31 UTC (rev 8273)
@@ -9,6 +9,8 @@
 import os.path
 import sys
 
+CHECKPKG_MODULE_NAME = "a template of a checkpkg module"
+
 # The following bit of code sets the correct path to Python libraries
 # distributed with GAR.
 path_list = [os.path.dirname(__file__),
@@ -57,7 +59,7 @@
   pkgnames = args
   # CheckpkgManager class abstracts away things such as the collection of
   # results.
-  check_manager = checkpkg.CheckpkgManager("a template of a checkpkg module",
+  check_manager = checkpkg.CheckpkgManager(CHECKPKG_MODULE_NAME,
                                            options.extractdir,
                                            pkgnames,
                                            options.debug)

Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py	2010-01-31 17:45:49 UTC (rev 8272)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py	2010-01-31 18:14:31 UTC (rev 8273)
@@ -107,7 +107,7 @@
   return options, set(args)
 
 
-class CheckpkgBase(object):
+class CheckpkgBase(opencsw.DirectoryFormatPackage):
   """This class has functionality overlapping with DirectoryFormatPackage
   from the opencsw.py library. The classes should be merged.
   """
@@ -116,46 +116,8 @@
     self.extractdir = extractdir
     self.pkgname = pkgname
     self.pkgpath = os.path.join(self.extractdir, self.pkgname)
+    super(CheckpkgBase, self).__init__(self.pkgpath)
 
-  def CheckPkgpathExists(self):
-    if not os.path.isdir(self.pkgpath):
-      raise PackageError("%s does not exist or is not a directory"
-                         % self.pkgpath)
-
-  def ListBinaries(self):
-    """Shells out to list all the binaries from a given package.
-
-    Original checkpkg code:
-
-    # #########################################
-    # # find all executables and dynamic libs,and list their filenames.
-    # listbinaries() {
-    #   if [ ! -d $1 ] ; then
-    #     print errmsg $1 not a directory
-    #     rm -rf $EXTRACTDIR
-    #     exit 1
-    #   fi
-    # 
-    #   find $1 -print | xargs file |grep ELF |nawk -F: '{print $1}'
-    # }
-    """
-    self.CheckPkgpathExists()
-    find_tmpl = "find %s -print | xargs file | grep ELF | nawk -F: '{print $1}'"
-    find_proc = subprocess.Popen(find_tmpl % self.pkgpath,
-                                 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()
-
-  def GetAllFilenames(self):
-    self.CheckPkgpathExists()
-    file_basenames = []
-    for root, dirs, files in os.walk(self.pkgpath):
-      file_basenames.extend(files)
-    return file_basenames
-
   def FormatDepsReport(self, missing_deps, surplus_deps, orphan_sonames):
     """To be removed."""
     namespace = {

Modified: csw/mgar/gar/v2/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw.py	2010-01-31 17:45:49 UTC (rev 8272)
+++ csw/mgar/gar/v2/lib/python/opencsw.py	2010-01-31 18:14:31 UTC (rev 8273)
@@ -643,7 +643,49 @@
     fd.close()
     return depends
 
+  def CheckPkgpathExists(self):
+    if not os.path.isdir(self.directory):
+      raise PackageError("%s does not exist or is not a directory"
+                         % self.directory)
 
+  def ListBinaries(self):
+    """Shells out to list all the binaries from a given package.
+
+    Original checkpkg code:
+
+    #########################################
+    # find all executables and dynamic libs,and list their filenames.
+    listbinaries() {
+      if [ ! -d $1 ] ; then
+        print errmsg $1 not a directory
+        rm -rf $EXTRACTDIR
+        exit 1
+      fi
+    
+      find $1 -print | xargs file |grep ELF |nawk -F: '{print $1}'
+    }
+
+    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()
+
+  def GetAllFilenames(self):
+    self.CheckPkgpathExists()
+    file_basenames = []
+    for root, dirs, files in os.walk(self.pkgpath):
+      file_basenames.extend(files)
+    return file_basenames
+
+
 class Pkgmap(object):
   """Represents the pkgmap of the package.
 


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