[csw-devel] SF.net SVN: gar:[13667] csw/mgar/gar/v2/lib/web/pkgdb_web.py
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Mon Mar 7 23:46:12 CET 2011
Revision: 13667
http://gar.svn.sourceforge.net/gar/?rev=13667&view=rev
Author: wahwah
Date: 2011-03-07 22:46:11 +0000 (Mon, 07 Mar 2011)
Log Message:
-----------
pkgdb-web: RESTful URL to retrieve pkg by pkgname
Returns a JSON data structure.
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-03-07 22:45:38 UTC (rev 13666)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py 2011-03-07 22:46:11 UTC (rev 13667)
@@ -32,6 +32,7 @@
'PkgnameByFilename',
# Query by catalog release, arch, OS release and catalogname
r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/catalognames/([^/]+)/', 'Srv4ByCatAndCatalogname',
+ r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames/([^/]+)/', 'Srv4ByCatAndPkgname',
r'/rest/srv4/([0-9a-f]{32})/', 'RestSrv4Detail',
)
@@ -302,6 +303,41 @@
raise web.internalerror(e)
+class Srv4ByCatAndPkgname(object):
+
+ def GET(self, catrel_name, arch_name, osrel_name, pkgname):
+ """Get a srv4 reference by catalog ane pkgname."""
+ configuration.SetUpSqlobjectConnection()
+ sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad(
+ osrel_name, arch_name, catrel_name)
+ join = [
+ sqlbuilder.INNERJOINOn(None,
+ models.Srv4FileInCatalog,
+ models.Srv4FileInCatalog.q.srv4file==models.Srv4FileStats.q.id),
+ sqlbuilder.INNERJOINOn(None,
+ models.Pkginst,
+ models.Pkginst.q.id==models.Srv4FileStats.q.pkginst),
+ ]
+ res = models.Srv4FileStats.select(
+ sqlobject.AND(
+ models.Srv4FileInCatalog.q.osrel==sqo_osrel,
+ models.Srv4FileInCatalog.q.arch==sqo_arch,
+ models.Srv4FileInCatalog.q.catrel==sqo_catrel,
+ models.Pkginst.q.pkgname==pkgname,
+ models.Srv4FileStats.q.use_to_generate_catalogs==True),
+ join=join,
+ )
+ try:
+ srv4 = res.getOne()
+ mimetype, data = srv4.GetRestRepr()
+ web.header('Content-type', mimetype)
+ return json.dumps(data)
+ except sqlobject.main.SQLObjectNotFound:
+ return json.dumps(None)
+ except sqlobject.dberrors.OperationalError, e:
+ raise web.internalerror(e)
+
+
web.webapi.internalerror = web.debugerror
# app = web.application(urls, globals())
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