[csw-devel] SF.net SVN: gar:[7912] csw/mgar/gar/v2/bin/checkpkg.d

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Fri Jan 8 01:37:22 CET 2010


Revision: 7912
          http://gar.svn.sourceforge.net/gar/?rev=7912&view=rev
Author:   wahwah
Date:     2010-01-08 00:37:22 +0000 (Fri, 08 Jan 2010)

Log Message:
-----------
mGAR v2: Part of output formatting moved to a function

Modified Paths:
--------------
    csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py
    csw/mgar/gar/v2/bin/checkpkg.d/checkpkg.py
    csw/mgar/gar/v2/bin/checkpkg.d/checkpkg_test.py

Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py	2010-01-07 23:34:57 UTC (rev 7911)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg-libs.py	2010-01-08 00:37:22 UTC (rev 7912)
@@ -186,31 +186,13 @@
         pkgs_by_filename,
         filenames_by_soname,
         pkg_by_any_filename)
+    print checker.FormatDepsReport(missing_deps,
+                                   surplus_deps,
+                                   orphan_sonames)
 
-    # TODO: Rewrite this using cheetah templates.
-    print "%s:" % pkgname
-    msg_printed = False
-    if missing_deps:
-      print "SUGGESTION: you may want to add some or all of the following as depends:"
-      print "   (Feel free to ignore SUNW or SPRO packages)"
-      for dep_pkgname in sorted(missing_deps):
-        print ">", dep_pkgname
-      msg_printed = True
-    if surplus_deps:
-      print "The following packages might be unnecessary dependencies:"
-      for dep_pkgname in surplus_deps:
-        print "? ", dep_pkgname
-      msg_printed = True
-    if orphan_sonames:
-      print "The following sonames don't belong to any package:"
-      for soname in sorted(orphan_sonames):
-        errors.append(checkpkg.Error("The following soname does't belong to "
-                                     "any package: %s" % soname))
-        print "! ", soname
-      msg_printed = True
-    if not msg_printed:
-      print "+  Dependencies of %s look good." % pkgname
-    print
+    for soname in orphan_sonames:
+      errors.append(checkpkg.Error("The following soname does't belong to "
+                                   "any package: %s" % checker.soname))
 
   if errors:
     for error in errors:

Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg.py	2010-01-07 23:34:57 UTC (rev 7911)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg.py	2010-01-08 00:37:22 UTC (rev 7912)
@@ -12,6 +12,7 @@
 import socket
 import sqlite3
 import subprocess
+import StringIO
 
 SYSTEM_PKGMAP = "/var/sadm/install/contents"
 WS_RE = re.compile(r"\s+")
@@ -112,7 +113,33 @@
     fd.close()
     return depends
 
+  def FormatDepsReport(self, missing_deps, surplus_deps, orphan_sonames):
+    """A intermediate version in which StringIO is used."""
+    s = StringIO.StringIO()
+    print >>s,  "%s:" % self.pkgname
+    msg_printed = False
+    if missing_deps:
+      print >>s,  "SUGGESTION: you may want to add some or all of the following as depends:"
+      print >>s,  "   (Feel free to ignore SUNW or SPRO packages)"
+      for dep_pkgname in sorted(missing_deps):
+        print >>s,  ">", dep_pkgname
+      msg_printed = True
+    if surplus_deps:
+      print >>s,  "The following packages might be unnecessary dependencies:"
+      for dep_pkgname in surplus_deps:
+        print >>s,  "? ", dep_pkgname
+      msg_printed = True
+    if orphan_sonames:
+      print >>s,  "The following sonames don't belong to any package:"
+      for soname in sorted(orphan_sonames):
+        print >>s,  "! ", soname
+      msg_printed = True
+    if not msg_printed:
+      print >>s,  "+  Dependencies of %s look good." % self.pkgname
+    s.seek(0)
+    return s.read()
 
+
 class SystemPkgmap(object):
   """A class to hold and manipulate the /var/sadm/install/contents file.
 

Modified: csw/mgar/gar/v2/bin/checkpkg.d/checkpkg_test.py
===================================================================
--- csw/mgar/gar/v2/bin/checkpkg.d/checkpkg_test.py	2010-01-07 23:34:57 UTC (rev 7911)
+++ csw/mgar/gar/v2/bin/checkpkg.d/checkpkg_test.py	2010-01-08 00:37:22 UTC (rev 7912)
@@ -3,6 +3,7 @@
 
 import unittest
 import mox
+import difflib
 import checkpkg
 import testdata.checkpkg_test_data_CSWmysql51rt as d1
 import testdata.checkpkg_test_data_CSWmysql51client as d2
@@ -434,5 +435,30 @@
         checkpkg.ParseDumpOutput(dump_2.DATA_DUMP_OUTPUT)["runpath"])
 
 
+class FormatDepsReportUnitTest(unittest.TestCase):
+
+  def AssertTextEqual(self, text1, text2):
+    difference = "\n".join(difflib.context_diff(text2.splitlines(), text1.splitlines()))
+    self.assertEqual(text1, text2, difference)
+
+  def test_1(self):
+    missing_deps = set([u'SUNWgss', u'*SUNWlxsl'])
+    surplus_deps = set(['CSWsudo', 'CSWlibxslt'])
+    orphan_sonames = set([])
+    testdata = (missing_deps, surplus_deps, orphan_sonames)
+    checker = checkpkg.CheckpkgBase("/tmp/nonexistent", "CSWfoo")
+    expected = u"""CSWfoo:
+SUGGESTION: you may want to add some or all of the following as depends:
+   (Feel free to ignore SUNW or SPRO packages)
+> *SUNWlxsl
+> SUNWgss
+The following packages might be unnecessary dependencies:
+?  CSWsudo
+?  CSWlibxslt
+"""
+    result = checker.FormatDepsReport(*testdata)
+    self.AssertTextEqual(result, expected)
+
+
 if __name__ == '__main__':
   unittest.main()


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