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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Feb 7 09:21:56 CET 2011


Revision: 13224
          http://gar.svn.sourceforge.net/gar/?rev=13224&view=rev
Author:   wahwah
Date:     2011-02-07 08:21:56 +0000 (Mon, 07 Feb 2011)

Log Message:
-----------
catalog-notifier: Terser catalog lists

Instead of printing one line per "catrel, arch, osrel" tuple, print one
line per catalog release, group by architecture, and omit the "SunOS"
part of the OS release name.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/catalog_notifier.py
    csw/mgar/gar/v2/lib/python/catalog_notifier_test.py

Modified: csw/mgar/gar/v2/lib/python/catalog_notifier.py
===================================================================
--- csw/mgar/gar/v2/lib/python/catalog_notifier.py	2011-02-07 08:20:41 UTC (rev 13223)
+++ csw/mgar/gar/v2/lib/python/catalog_notifier.py	2011-02-07 08:21:56 UTC (rev 13224)
@@ -20,16 +20,36 @@
 
 REPORT_TMPL = u"""Catalog update report for $email
 Catalog URL: $url
+#import re
+#def CatalogList($catalogs)
+#set $by_catrel = {}
+#set $unused = [by_catrel.setdefault(x[0], []).append(x[1:]) for x in $catalogs]
+#for catrel in $by_catrel:
+  - $catrel: #
+#set $by_arch = {}
+#set $unused = [by_arch.setdefault(x[0], []).append(x[1:]) for x in $by_catrel[$catrel]]
+#set $first = True
+#for arch in $by_arch:
+#if not $first
+, #
+#else
+#set $first = False
+#end if
+$arch (#
+#echo ", ".join([re.sub(r'^.*OS', '', x[0]) for x in $by_arch[$arch]]) + ")"
+#end for
+
+#end for
+#end def
 #if "new_pkgs" in $pkg_data
 
 New packages:
 #for basename in $pkg_data["new_pkgs"]
 * $basename
   In catalogs:
-#for catalog in $sorted($pkg_data["new_pkgs"][basename]["catalogs"])
-  - $catalog[0] $catalog[1] $catalog[2]
+#set $catalogs = $sorted($pkg_data["new_pkgs"][basename]["catalogs"])
+$CatalogList($catalogs)
 #end for
-#end for
 #end if
 #if "removed_pkgs" in $pkg_data
 
@@ -37,10 +57,9 @@
 #for basename in $pkg_data["removed_pkgs"]
 * $basename
   From catalogs:
-#for catalog in $sorted($pkg_data["removed_pkgs"][basename]["catalogs"])
-  - $catalog[0] $catalog[1] $catalog[2]
+#set $catalogs = $sorted($pkg_data["removed_pkgs"][basename]["catalogs"])
+$CatalogList($catalogs)
 #end for
-#end for
 #end if
 #if "upgraded_pkg" in $pkg_data
 
@@ -51,10 +70,9 @@
 #end for
 + $pkg_data["upgraded_pkg"][basename]["to_pkg"]["file_basename"]
   In catalogs:
-#for catalog in $sorted($pkg_data["upgraded_pkg"][basename]["catalogs"])
-  - $catalog[0] $catalog[1] $catalog[2]
+#set $catalogs = $sorted($pkg_data["upgraded_pkg"][basename]["catalogs"])
+$CatalogList($catalogs)
 #end for
-#end for
 #end if
 #if "lost_pkg" in $pkg_data
 
@@ -64,10 +82,9 @@
 - $pkg_data["lost_pkg"][basename]["from_pkg"][from_basename]["file_basename"]
 #end for
   In catalogs:
-#for catalog in $sorted($pkg_data["lost_pkg"][basename]["catalogs"])
-  - $catalog[0] $catalog[1] $catalog[2]
+#set $catalogs = $sorted($pkg_data["lost_pkg"][basename]["catalogs"])
+$CatalogList($catalogs)
 #end for
-#end for
 #end if
 #if "got_pkg" in $pkg_data
 
@@ -75,10 +92,9 @@
 #for basename in $pkg_data["got_pkg"]
 * $basename
   In catalogs:
-#for catalog in $sorted($pkg_data["got_pkg"][basename]["catalogs"])
-  - $catalog[0] $catalog[1] $catalog[2]
+#set $catalogs = $sorted($pkg_data["got_pkg"][basename]["catalogs"])
+$CatalogList($catalogs)
 #end for
-#end for
 #end if
 """
 

Modified: csw/mgar/gar/v2/lib/python/catalog_notifier_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/catalog_notifier_test.py	2011-02-07 08:20:41 UTC (rev 13223)
+++ csw/mgar/gar/v2/lib/python/catalog_notifier_test.py	2011-02-07 08:21:56 UTC (rev 13224)
@@ -7,6 +7,7 @@
 import catalog_test
 import copy
 import pprint
+import rest
 
 
 class NotificationFormatterTest(mox.MoxTestBase):
@@ -14,7 +15,7 @@
   def disabled_testOne(self):
     """This tested too much."""
     f = catalog_notifier.NotificationFormatter()
-    rest_client_mock = self.mox.CreateMock(catalog_notifier.RestClient)
+    rest_client_mock = self.mox.CreateMock(rest.RestClient)
     url = "http://www.example.com/opencsw/"
     cat_a = self.mox.CreateMock(catalog.OpencswCatalog)
     cat_b = self.mox.CreateMock(catalog.OpencswCatalog)
@@ -33,19 +34,43 @@
 
   def test_GetPkgsByMaintainerNew(self):
     f = catalog_notifier.NotificationFormatter()
-    rest_client_mock = self.mox.CreateMock(catalog_notifier.RestClient)
+    rest_client_mock = self.mox.CreateMock(rest.RestClient)
     cat_a = self.mox.CreateMock(catalog.OpencswCatalog)
     cat_b = self.mox.CreateMock(catalog.OpencswCatalog)
     catalogs = [
         ("fossil", "amd65", "SolarOS5.12", cat_a, cat_b),
+        ("fossil", "amd65", "SolarOS5.13", cat_a, cat_b),
+        ("fossil", "amd67", "SolarOS5.12", cat_a, cat_b),
+        ("rock",   "amd65", "SolarOS5.12", cat_a, cat_b),
     ]
     rest_client_mock.GetMaintainerByMd5('cfe40c06e994f6e8d3b191396d0365cb').AndReturn(
         {"maintainer_email": "joe at example.com"}
     )
+    rest_client_mock.GetMaintainerByMd5('cfe40c06e994f6e8d3b191396d0365cb').AndReturn(
+        {"maintainer_email": "joe at example.com"}
+    )
+    rest_client_mock.GetMaintainerByMd5('cfe40c06e994f6e8d3b191396d0365cb').AndReturn(
+        {"maintainer_email": "joe at example.com"}
+    )
+    rest_client_mock.GetMaintainerByMd5('cfe40c06e994f6e8d3b191396d0365cb').AndReturn(
+        {"maintainer_email": "joe at example.com"}
+    )
     cat_a.GetDataByCatalogname().AndReturn({})
     cat_b.GetDataByCatalogname().AndReturn({
       "syslog_ng": catalog_test.PKG_STRUCT_1,
     })
+    cat_a.GetDataByCatalogname().AndReturn({})
+    cat_b.GetDataByCatalogname().AndReturn({
+      "syslog_ng": catalog_test.PKG_STRUCT_1,
+    })
+    cat_a.GetDataByCatalogname().AndReturn({})
+    cat_b.GetDataByCatalogname().AndReturn({
+      "syslog_ng": catalog_test.PKG_STRUCT_1,
+    })
+    cat_a.GetDataByCatalogname().AndReturn({})
+    cat_b.GetDataByCatalogname().AndReturn({
+      "syslog_ng": catalog_test.PKG_STRUCT_1,
+    })
     self.mox.ReplayAll()
     expected = {'joe at example.com': {
       'new_pkgs': {
@@ -53,20 +78,23 @@
           "pkg": catalog_test.PKG_STRUCT_1,
           "catalogs": [
             ("fossil", "amd65", "SolarOS5.12"),
+            ("fossil", "amd65", "SolarOS5.13"),
+            ("fossil", "amd67", "SolarOS5.12"),
+            ("rock",   "amd65", "SolarOS5.12"),
           ],
         },
       }}
     }
-    self.assertEqual(
-        expected,
-        f._GetPkgsByMaintainer(catalogs, rest_client_mock))
-    expected_text = u"""aa"""
+    result = f._GetPkgsByMaintainer(catalogs, rest_client_mock)
+    self.assertEqual(expected, result)
     # Uncomment to see rendered template
-    # print f._RenderForMaintainer(expected["joe at example.com"])
+    # print f._RenderForMaintainer(
+    #     result["joe at example.com"], "joe at example.com",
+    #     "http://mirror.example.com")
 
   def test_GetPkgsByMaintainerRemoved(self):
     f = catalog_notifier.NotificationFormatter()
-    rest_client_mock = self.mox.CreateMock(catalog_notifier.RestClient)
+    rest_client_mock = self.mox.CreateMock(rest.RestClient)
     cat_a = self.mox.CreateMock(catalog.OpencswCatalog)
     cat_b = self.mox.CreateMock(catalog.OpencswCatalog)
     catalogs = [
@@ -95,11 +123,14 @@
         f._GetPkgsByMaintainer(catalogs, rest_client_mock))
     expected_text = u"""aa"""
     # Uncomment to see rendered template
-    # print f._RenderForMaintainer(expected["joe at example.com"])
+    # print f._RenderForMaintainer(
+    #     expected["joe at example.com"],
+    #     "joe at example.com",
+    #     "http://mirror.example.com")
 
   def test_GetPkgsByMaintainerTakeover(self):
     f = catalog_notifier.NotificationFormatter()
-    rest_client_mock = self.mox.CreateMock(catalog_notifier.RestClient)
+    rest_client_mock = self.mox.CreateMock(rest.RestClient)
     cat_a = self.mox.CreateMock(catalog.OpencswCatalog)
     cat_b = self.mox.CreateMock(catalog.OpencswCatalog)
     catalogs = [
@@ -147,7 +178,7 @@
 
   def test_GetPkgsByMaintainerUpgrade(self):
     f = catalog_notifier.NotificationFormatter()
-    rest_client_mock = self.mox.CreateMock(catalog_notifier.RestClient)
+    rest_client_mock = self.mox.CreateMock(rest.RestClient)
     cat_a = self.mox.CreateMock(catalog.OpencswCatalog)
     cat_b = self.mox.CreateMock(catalog.OpencswCatalog)
     catalogs = [


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