[csw-devel] SF.net SVN: gar:[15980] csw/mgar/gar/v2/lib
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Tue Oct 25 09:26:23 CEST 2011
Revision: 15980
http://gar.svn.sourceforge.net/gar/?rev=15980&view=rev
Author: wahwah
Date: 2011-10-25 07:26:23 +0000 (Tue, 25 Oct 2011)
Log Message:
-----------
pkgdb-web: Return the full stats object via REST
When calling the package details, return (serialized) data structure,
containing all information about the package. It allows, among other things,
third parties to write package checks.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/models.py
csw/mgar/gar/v2/lib/web/pkgdb_web.py
Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py 2011-10-24 22:37:03 UTC (rev 15979)
+++ csw/mgar/gar/v2/lib/python/models.py 2011-10-25 07:26:23 UTC (rev 15980)
@@ -248,6 +248,12 @@
return vendor_url
def GetRestRepr(self):
+ """The returned data structure needs a bit of fiddling.
+
+ The frozenset and datatime.datetime objects are returned, and require
+ a specialized JSON serializer. See lib/web/pkgdb_web.py for the
+ implementation.
+ """
mimetype = "application/x-vnd.opencsw.pkg;type=srv4-detail"
data = {
'arch': self.arch.name,
@@ -270,6 +276,7 @@
# 'in_catalogs': unicode([unicode(x) for x in self.in_catalogs]),
'vendor_url': self.GetVendorUrl(),
'repository_url': self.GetSvnUrl(),
+ 'pkg_stats': self.GetStatsStruct(),
}
return mimetype, data
Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py 2011-10-24 22:37:03 UTC (rev 15979)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py 2011-10-25 07:26:23 UTC (rev 15980)
@@ -273,12 +273,21 @@
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()
web.header('Content-type', mimetype)
web.header('Access-Control-Allow-Origin', '*')
- return json.dumps(data_structure)
+ return json.dumps(data_structure, cls=PkgStatsEncoder)
except sqlobject.main.SQLObjectNotFound, e:
raise web.notfound()
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