[csw-devel] SF.net SVN: gar:[15988] csw/mgar/gar/v2/lib/web/pkgdb_web.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Oct 25 17:17:53 CEST 2011


Revision: 15988
          http://gar.svn.sourceforge.net/gar/?rev=15988&view=rev
Author:   wahwah
Date:     2011-10-25 15:17:53 +0000 (Tue, 25 Oct 2011)
Log Message:
-----------
pkgdb-web: Serve full pkg stats separately

Implementing the suggestion from:
http://lists.opencsw.org/pipermail/maintainers/2011-October/015580.html

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/web/pkgdb_web.py

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-10-25 14:40:37 UTC (rev 15987)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-10-25 15:17:53 UTC (rev 15988)
@@ -35,6 +35,7 @@
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames/([^/]+)/', 'Srv4ByCatAndPkgname',
   r'/rest/srv4/([0-9a-f]{32})/', 'RestSrv4Detail',
   r'/rest/srv4/([0-9a-f]{32})/files/', 'RestSrv4DetailFiles',
+  r'/rest/srv4/([0-9a-f]{32})/pkg-stats/', 'RestSrv4FullStats',
 )
 
 # render = web.template.render('templates/')
@@ -273,22 +274,12 @@
 
   def GET(self, md5_sum):
     ConnectToDatabase()
-    class PkgStatsEncoder(json.JSONEncoder):
-      def default(self, obj):
-        if isinstance(obj, frozenset):
-          # Python 2.6 doesn't have the dictionary comprehension
-          # return {x: None for x in obj}
-          return list(obj)
-        if isinstance(obj, datetime.datetime):
-          return obj.isoformat()
-        return json.JSONEncoder.default(self, obj)
     try:
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       mimetype, data_structure = pkg.GetRestRepr()
-      data_structure["pkg_stats"] = pkg.GetStatsStruct()
       web.header('Content-type', mimetype)
       web.header('Access-Control-Allow-Origin', '*')
-      return json.dumps(data_structure, cls=PkgStatsEncoder)
+      return json.dumps(data_structure)
     except sqlobject.main.SQLObjectNotFound, e:
       raise web.notfound()
 
@@ -314,6 +305,28 @@
       raise web.notfound()
 
 
+class RestSrv4FullStats(object):
+
+  def GET(self, md5_sum):
+    ConnectToDatabase()
+    class PkgStatsEncoder(json.JSONEncoder):
+      def default(self, obj):
+        if isinstance(obj, frozenset):
+          # Python 2.6 doesn't have the dictionary comprehension
+          # return {x: None for x in obj}
+          return list(obj)
+        if isinstance(obj, datetime.datetime):
+          return obj.isoformat()
+        return json.JSONEncoder.default(self, obj)
+    try:
+      pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
+      data_structure = pkg.GetStatsStruct()
+      web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=pkg-stats')
+      return json.dumps(data_structure, cls=PkgStatsEncoder)
+    except sqlobject.main.SQLObjectNotFound, e:
+      raise web.notfound()
+
+
 class Srv4ByCatAndCatalogname(object):
 
   def GET(self, catrel_name, arch_name, osrel_name, catalogname):

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