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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sat Mar 13 09:35:34 CET 2010


Revision: 9127
          http://gar.svn.sourceforge.net/gar/?rev=9127&view=rev
Author:   wahwah
Date:     2010-03-13 08:35:34 +0000 (Sat, 13 Mar 2010)

Log Message:
-----------
mGAR v2: checkpkg, moving the IndividualCheckInterface class to the module top level, removing the direct use of SystemPkgmap from checkpkg.GetLinesBySoname()

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-basic.py
    csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-libs.py
    csw/mgar/gar/v2/lib/python/checkpkg.py
    csw/mgar/gar/v2/lib/python/checkpkg_test.py
    csw/mgar/gar/v2/lib/python/opencsw.py

Property Changed:
----------------
    csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-basic.py

Modified: csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-basic.py
===================================================================
--- csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-basic.py	2010-03-13 08:32:51 UTC (rev 9126)
+++ csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-basic.py	2010-03-13 08:35:34 UTC (rev 9127)
@@ -1,5 +1,5 @@
 #!/opt/csw/bin/python2.6
-# $Id: checkpkg-you-can-write-your-own.py 8571 2010-02-16 09:05:51Z wahwah $
+# $Id$
 
 """This is a dummy module. You can use it as a boilerplate for your own modules.
 


Property changes on: csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-basic.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-libs.py
===================================================================
--- csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-libs.py	2010-03-13 08:32:51 UTC (rev 9126)
+++ csw/mgar/gar/v2/lib/checkpkg.d/checkpkg-libs.py	2010-03-13 08:35:34 UTC (rev 9127)
@@ -64,8 +64,11 @@
   pkgmap = checkpkg.SystemPkgmap()
   logging.debug("Determining the soname-package relationships.")
   # lines by soname is an equivalent of $EXTRACTDIR/shortcatalog
+  runpath_data_by_soname = {}
+  for soname in needed_sonames:
+    runpath_data_by_soname[soname] = pkgmap.GetPkgmapLineByBasename(soname)
   lines_by_soname = checkpkg.GetLinesBySoname(
-      pkgmap, needed_sonames, runpath_by_needed_soname, isalist)
+      runpath_data_by_soname, needed_sonames, runpath_by_needed_soname, isalist)
 
   # Creating a map from files to packages.
   pkgs_by_filename = {}

Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py	2010-03-13 08:32:51 UTC (rev 9126)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py	2010-03-13 08:35:34 UTC (rev 9127)
@@ -600,7 +600,9 @@
   return runpath
 
 
-def GetLinesBySoname(pkgmap, needed_sonames, runpath_by_needed_soname, isalist):
+def GetLinesBySoname(runpath_data_by_soname,
+                     needed_sonames,
+                     runpath_by_needed_soname, isalist):
   """Works out which system pkgmap lines correspond to given sonames."""
   lines_by_soname = {}
   for soname in needed_sonames:
@@ -611,11 +613,11 @@
       runpath = SanitizeRunpath(runpath)
       runpath_list = ExpandRunpath(runpath, isalist)
       runpath_list = Emulate64BitSymlinks(runpath_list)
-      soname_runpath_data = pkgmap.GetPkgmapLineByBasename(soname)
       # Emulating the install time symlinks, for instance, if the prototype contains
       # /opt/csw/lib/i386/foo.so.0 and /opt/csw/lib/i386 is a symlink to ".",
-      # the shared library ends up in /opt/csw/lib/foo.so.0 and should be findable even when
-      # RPATH does not contain $ISALIST.
+      # the shared library ends up in /opt/csw/lib/foo.so.0 and should be
+      # findable even when RPATH does not contain $ISALIST.
+      soname_runpath_data = runpath_data_by_soname[soname]
       new_soname_runpath_data = {}
       for p in soname_runpath_data:
         expanded_p_list = Emulate64BitSymlinks([p])
@@ -803,46 +805,53 @@
     return errors
 
 
-class CheckpkgManager2(CheckpkgManagerBase):
-  """The second incarnation of the checkpkg manager.
+class CheckInterfaceBase(object):
+  """Base class for check proxies.
 
-  Implements the API to be used by checking functions.
+  It wraps access to the /var/sadm/install/contents cache.
+  """
 
-  Its purpose is to reduce the amount of boilerplate code and allow for easier
-  unit test writing.
+  def __init__(self, system_pkgmap=None):
+    self.system_pkgmap = system_pkgmap
+    if not self.system_pkgmap:
+      self.system_pkgmap = SystemPkgmap()
+
+
+class IndividualCheckInterface(CheckInterfaceBase):
+  """To be passed to the checking functions.
+
+  Wraps the creation of CheckpkgTag objects.
   """
-  class CheckInterfaceBase(object):
-    """Base class for check proxies.
 
-    It wraps access to the /var/sadm/install/contents cache.
-    """
+  def __init__(self, pkgname, system_pkgmap=None):
+    super(IndividualCheckInterface, self).__init__(system_pkgmap)
+    self.pkgname = pkgname
+    self.errors = []
 
-    def __init__(self, system_pkgmap):
-      self.system_pkgmap = system_pkgmap
+  def ReportError(self, tag_name, tag_info=None, msg=None):
+    tag = CheckpkgTag(self.pkgname, tag_name, tag_info, msg)
+    self.errors.append(tag)
 
-  class IndividualCheckInterface(CheckInterfaceBase):
-    """To be passed to the checking functions.
 
-    Wraps the creation of CheckpkgTag objects.
-    """
+def SetCheckInterface(object):
+  """To be passed to set checking functions."""
+  def __init__(self, system_pkgmap):
+    super(SetCheckInterface, self).__init__(system_pkgmap)
+    self.errors = []
 
-    def __init__(self, pkgname):
-      self.pkgname = pkgname
-      self.errors = []
+  def ReportError(self, pkgname, tag_name, tag_info=None, msg=None):
+    tag = CheckpkgTag(pkgname, tag_name, tag_info, msg)
+    self.errors.append(tag)
 
-    def ReportError(self, tag_name, tag_info=None, msg=None):
-      self.errors.append(
-          CheckpkgTag(self.pkgname, tag_name, tag_info, msg))
 
-  def SetCheckInterface(object):
-    """To be bassed to set checking functions."""
-    def __init__(self):
-      self.errors = []
+class CheckpkgManager2(CheckpkgManagerBase):
+  """The second incarnation of the checkpkg manager.
 
-    def ReportError(self, pkgname, tag_name, tag_info=None, msg=None):
-      self.errors.append(
-          CheckpkgTag(pkgname, tag_name, tag_info, msg))
+  Implements the API to be used by checking functions.
 
+  Its purpose is to reduce the amount of boilerplate code and allow for easier
+  unit test writing.
+  """
   def _RegisterIndividualCheck(self, function):
     self.individual_checks.append(function)
 
@@ -875,7 +884,7 @@
       for function in self.individual_checks:
         all_stats = pkg_data.GetAllStats()
         pkgname = all_stats["basic_stats"]["pkgname"]
-        check_interface = self.IndividualCheckInterface(pkgname)
+        check_interface = IndividualCheckInterface(pkgname)
         logger = logging.getLogger("%s-%s" % (pkgname, function.__name__))
         logger.debug("Calling %s", function.__name__)
         function(all_stats, check_interface, logger=logger)
@@ -885,7 +894,7 @@
     for function in self.set_checks:
       pkgs_data = [x.GetAllStats() for x in packages_data]
       logger = logging.getLogger("SetCheck-%s" % (function.__name__,))
-      check_interface = self.SetCheckInterface()
+      check_interface = SetCheckInterface()
       logger.debug("Calling %s", function.__name__)
       function(pkgs_data, check_interface, logger)
       if check_interface.errors:

Modified: csw/mgar/gar/v2/lib/python/checkpkg_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_test.py	2010-03-13 08:32:51 UTC (rev 9126)
+++ csw/mgar/gar/v2/lib/python/checkpkg_test.py	2010-03-13 08:35:34 UTC (rev 9127)
@@ -292,14 +292,6 @@
 
 class GetLinesBySonameUnitTest(unittest.TestCase):
 
-  class PkgmapStub(object):
-
-    def __init__(self, cache):
-      self.cache = cache
-
-    def GetPkgmapLineByBasename(self, soname):
-      return self.cache[soname]
-
   def setUp(self):
     self.pkgmap_mocker = mox.Mox()
 
@@ -377,62 +369,52 @@
 
   def testGetLinesBySoname(self):
     expected = {'foo.so.1': '/opt/csw/lib/isa-value-1/foo.so.1 foo'}
-    pkgmap = self.pkgmap_mocker.CreateMock(checkpkg.SystemPkgmap)
-    pkgmap.GetPkgmapLineByBasename("foo")
-    lines1 = {"/opt/csw/lib/isa-value-1": "/opt/csw/lib/isa-value-1/foo.so.1 foo",
-              "/usr/lib":                  "/usr/lib/foo.so.1 foo"}
-    # pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    self.pkgmap_mocker.ReplayAll()
-    pkgmap.GetPkgmapLineByBasename("foo")
+    runpath_data_by_soname = {
+        "foo.so.1": {
+          "/opt/csw/lib/isa-value-1": "/opt/csw/lib/isa-value-1/foo.so.1 foo",
+          "/usr/lib":                 "/usr/lib/foo.so.1 foo"},
+    }
     needed_sonames = set(["foo.so.1"])
     runpath_by_needed_soname = {"foo.so.1": ["/opt/csw/lib/$ISALIST", "/usr/lib"]}
     isalist = ["isa-value-1", "isa-value-2"]
-    result = checkpkg.GetLinesBySoname(pkgmap, needed_sonames, runpath_by_needed_soname, isalist)
-    self.pkgmap_mocker.VerifyAll()
+    result = checkpkg.GetLinesBySoname(runpath_data_by_soname, needed_sonames,
+                                       runpath_by_needed_soname, isalist)
     self.assertEqual(expected, result)
 
   def testGetLinesBySoname_3(self):
     expected = {'foo.so.1': '/opt/csw/lib/isa-value-1/foo.so.1 foo'}
-    pkgmap = self.pkgmap_mocker.CreateMock(checkpkg.SystemPkgmap)
-    pkgmap.GetPkgmapLineByBasename("foo")
-    lines1 = {
-        "/opt/csw/lib/isa-value-1": "/opt/csw/lib/isa-value-1/foo.so.1 foo",
-        "/opt/csw/lib":             "/opt/csw/lib/foo.so.1 foo",
-        "/usr/lib":                 "/usr/lib/foo.so.1 foo"}
-    # pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    self.pkgmap_mocker.ReplayAll()
-    pkgmap.GetPkgmapLineByBasename("foo")
+    runpath_data_by_soname = {
+        "foo.so.1": {
+          "/opt/csw/lib/isa-value-1": "/opt/csw/lib/isa-value-1/foo.so.1 foo",
+          "/opt/csw/lib":             "/opt/csw/lib/foo.so.1 foo",
+          "/usr/lib":                 "/usr/lib/foo.so.1 foo",
+        }
+    }
     needed_sonames = set(["foo.so.1"])
     runpath_by_needed_soname = {
         "foo.so.1": ["/opt/csw/lib/$ISALIST", "/usr/lib"]}
     isalist = ["isa-value-1", "isa-value-2"]
-    result = checkpkg.GetLinesBySoname(
-        pkgmap, needed_sonames, runpath_by_needed_soname, isalist)
-    self.pkgmap_mocker.VerifyAll()
+    result = checkpkg.GetLinesBySoname(runpath_data_by_soname, needed_sonames,
+                                       runpath_by_needed_soname, isalist)
     self.assertEqual(expected, result)
 
   def testGetLinesBySoname_4(self):
     """A more complex test, four ISAs."""
     expected = {'foo.so.1': '/opt/csw/lib/isa-value-1/foo.so.1 foo'}
-    pkgmap = self.pkgmap_mocker.CreateMock(checkpkg.SystemPkgmap)
-    pkgmap.GetPkgmapLineByBasename("foo")
-    lines1 = {
-        "/opt/csw/lib/isa-value-1":
-            "/opt/csw/lib/isa-value-1/foo.so.1 foo",
-        "/opt/csw/mysql5/lib/isa-value-2":
-            "/opt/csw/mysql5/lib/isa-value-2/foo.so.1 foo",
-        "/opt/csw/mysql5/lib/isa-value-1":
-            "/opt/csw/mysql5/lib/isa-value-1/foo.so.1 foo",
-        "/opt/csw/lib":
-            "/opt/csw/lib/foo.so.1 foo",
-        "/usr/lib":
-            "/usr/lib/foo.so.1 foo"}
-    pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    self.pkgmap_mocker.ReplayAll()
-    pkgmap.GetPkgmapLineByBasename("foo")
+    runpath_data_by_soname = {
+        "foo.so.1": {
+          "/opt/csw/lib/isa-value-1":
+              "/opt/csw/lib/isa-value-1/foo.so.1 foo",
+          "/opt/csw/mysql5/lib/isa-value-2":
+              "/opt/csw/mysql5/lib/isa-value-2/foo.so.1 foo",
+          "/opt/csw/mysql5/lib/isa-value-1":
+              "/opt/csw/mysql5/lib/isa-value-1/foo.so.1 foo",
+          "/opt/csw/lib":
+              "/opt/csw/lib/foo.so.1 foo",
+          "/usr/lib":
+              "/usr/lib/foo.so.1 foo"
+        }
+    }
     needed_sonames = set(["foo.so.1"])
     runpath_by_needed_soname = {
         "foo.so.1": ["/opt/csw/mysql5/lib/$ISALIST/mysql",
@@ -440,41 +422,40 @@
                      "/usr/lib"]}
     isalist = ["isa-value-1", "isa-value-2"]
     result = checkpkg.GetLinesBySoname(
-        pkgmap, needed_sonames, runpath_by_needed_soname, isalist)
+        runpath_data_by_soname, needed_sonames, runpath_by_needed_soname, isalist)
     self.pkgmap_mocker.VerifyAll()
     self.assertEqual(expected, result)
 
   def testGetLinesBySoname_5(self):
-    """Based on CSWmysql5client on build8x."""
+    """Based on CSWmysql5client on build8x (5)."""
     soname = u'libm.so.1'
     expected = {u'libm.so.1': u'/usr/lib/libm.so.1 f none 0755 root bin '
                               u'99844 3884 1050525375 SUNWlibms\n'}
-
-    pkgmap_stub = self.PkgmapStub(d6.DATA_PKGMAP_CACHE)
+    runpath_data_by_soname = d6.DATA_PKGMAP_CACHE
     (needed_sonames,
      binaries_by_soname,
      runpath_by_needed_soname) = checkpkg.BuildIndexesBySoname(
          d6.DATA_NEEDED_SONAMES_BY_BINARY)
     result = checkpkg.GetLinesBySoname(
-        pkgmap_stub,
+        runpath_data_by_soname,
         set([soname]),
         runpath_by_needed_soname,
         d6.DATA_ISALIST)
     self.assertEqual(expected, result)
 
   def testGetLinesBySoname_6(self):
-    """Based on CSWmysql5client on build8x."""
+    """Based on CSWmysql5client on build8x (6)."""
     soname = u'libz.so.1'
     expected = {
         u'libz.so.1': u'/opt/csw/lib/pentium_pro+mmx/libz.so.1=libz.so.1.2.3 '
         u's none CSWzlib\n'}
-    pkgmap_stub = self.PkgmapStub(d6.DATA_PKGMAP_CACHE)
+    runpath_data_by_soname = d6.DATA_PKGMAP_CACHE
     (needed_sonames,
      binaries_by_soname,
      runpath_by_needed_soname) = checkpkg.BuildIndexesBySoname(
          d6.DATA_NEEDED_SONAMES_BY_BINARY)
     result = checkpkg.GetLinesBySoname(
-        pkgmap_stub,
+        runpath_data_by_soname,
         set([soname]),
         runpath_by_needed_soname,
         d6.DATA_ISALIST)
@@ -488,7 +469,7 @@
         u'libncursesw.so.5':
           u'/opt/csw/lib/amd64/libncursesw.so.5=libncursesw.so.5.7 '
           u's none CSWncurses\n'}
-    pkgmap_stub = self.PkgmapStub(d6.DATA_PKGMAP_CACHE)
+    runpath_data_by_soname = d6.DATA_PKGMAP_CACHE
     (needed_sonames,
      binaries_by_soname,
      runpath_by_needed_soname) = checkpkg.BuildIndexesBySoname(
@@ -497,7 +478,7 @@
     isalist = ['amd64', 'pentium_pro+mmx', 'pentium_pro', 'pentium+mmx',
                'pentium', 'i486', 'i386', 'i86']
     result = checkpkg.GetLinesBySoname(
-        pkgmap_stub,
+        runpath_data_by_soname,
         set([soname]),
         runpath_by_needed_soname,
         isalist)
@@ -505,16 +486,17 @@
 
   def testGetLinesBySoname_8(self):
     expected = {'foo.so.1': '/opt/csw/postgresql/lib/foo.so.1 foo'}
-    lines1 = {"/opt/csw/postgresql/lib": "/opt/csw/postgresql/lib/foo.so.1 foo"}
-    pkgmap = self.pkgmap_mocker.CreateMock(checkpkg.SystemPkgmap)
-    pkgmap.GetPkgmapLineByBasename("foo.so.1").AndReturn(lines1)
-    self.pkgmap_mocker.ReplayAll()
+    runpath_data_by_soname = {
+        "foo.so.1": {
+          "/opt/csw/postgresql/lib": "/opt/csw/postgresql/lib/foo.so.1 foo",
+        }
+    }
     needed_sonames = set(["foo.so.1"])
     runpath_by_needed_soname = {
         "foo.so.1": ["/opt/csw/postgresql/lib/", "/usr/lib"]}
     isalist = ["isa-value-1", "isa-value-2"]
-    result = checkpkg.GetLinesBySoname(pkgmap, needed_sonames, runpath_by_needed_soname, isalist)
-    self.pkgmap_mocker.VerifyAll()
+    result = checkpkg.GetLinesBySoname(
+        runpath_data_by_soname, needed_sonames, runpath_by_needed_soname, isalist)
     self.assertEqual(expected, result)
 
   def testGetLinesBySoname_9(self):
@@ -524,16 +506,16 @@
     end up in /opt/csw/lib instead.
     """
     expected = {'foo.so.0': '/opt/csw/lib/i386/foo.so.0 foo'}
-    lines1 = {"/opt/csw/lib/i386": "/opt/csw/lib/i386/foo.so.0 foo"}
-    pkgmap = self.pkgmap_mocker.CreateMock(checkpkg.SystemPkgmap)
-    pkgmap.GetPkgmapLineByBasename("foo.so.0").AndReturn(lines1)
-    self.pkgmap_mocker.ReplayAll()
+    runpath_data_by_soname = {
+        "foo.so.0": {
+          "/opt/csw/lib/i386": "/opt/csw/lib/i386/foo.so.0 foo",
+        }
+    }
     needed_sonames = set(["foo.so.0"])
     runpath_by_needed_soname = {"foo.so.0": ["/opt/csw/lib", "/usr/lib"]}
     isalist = ["isa-value-1", "isa-value-2"]
     result = checkpkg.GetLinesBySoname(
-        pkgmap, needed_sonames, runpath_by_needed_soname, isalist)
-    self.pkgmap_mocker.VerifyAll()
+        runpath_data_by_soname, needed_sonames, runpath_by_needed_soname, isalist)
     self.assertEqual(expected, result)
 
   def testSanitizeRunpath_1(self):

Modified: csw/mgar/gar/v2/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw.py	2010-03-13 08:32:51 UTC (rev 9126)
+++ csw/mgar/gar/v2/lib/python/opencsw.py	2010-03-13 08:35:34 UTC (rev 9127)
@@ -312,7 +312,7 @@
 
   def FormatMail(self):
     return self._FormatMail(self.paths, self.pkgnames, self.sender,
-                             self.release_mgr, self.release_cc)
+                            self.release_mgr, self.release_cc)
 
   def _GetPkgsData(self, paths):
     """Gathering package info, grouping packages that are upgraded together."""


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