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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Jan 27 12:50:18 CET 2011


Revision: 13095
          http://gar.svn.sourceforge.net/gar/?rev=13095&view=rev
Author:   wahwah
Date:     2011-01-27 11:50:17 +0000 (Thu, 27 Jan 2011)

Log Message:
-----------
pkgdb_web: Added an interface for individual srv4

It would make sense to add some sort of standard methods to each model, to be
used with RESTful interfaces.  Such methods would return representations of
each object intended for RESTful interfaces, i.e. - json serializable.

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-01-26 14:12:34 UTC (rev 13094)
+++ csw/mgar/gar/v2/lib/python/models.py	2011-01-27 11:50:17 UTC (rev 13095)
@@ -207,7 +207,27 @@
   def GetStatsStruct(self):
     return cPickle.loads(str(self.data_obj.pickle))
 
+  def GetRestRepr(self):
+    mimetype = "application/x-vnd.opencsw.pkg;type=srv4-detail"
+    data = {
+        'catalogname': self.catalogname,
+        'basename': self.basename,
+        'md5_sum': self.md5_sum,
+        'size': self.size,
+        'maintainer_email': self.maintainer.email,
+        'maintainer_full_name': self.maintainer.full_name,
+        'version_string': self.version_string,
+        'arch': self.arch.name,
+        'pkgname': self.pkginst.pkgname,
+        'mtime': unicode(self.mtime),
+        'osrel': self.os_rel.short_name,
+        'rev': self.rev,
+        'filename_arch': self.filename_arch.name,
+        # 'in_catalogs': unicode([unicode(x) for x in self.in_catalogs]),
+    }
+    return mimetype, data
 
+
 class CheckpkgErrorTagMixin(object):
 
   def ToGarSyntax(self):

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-01-26 14:12:34 UTC (rev 13094)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-01-27 11:50:17 UTC (rev 13095)
@@ -23,6 +23,7 @@
   r'/maintainers/(\d+)/checkpkg/', 'MaintainerCheckpkgReport',
   r'/error-tags/', 'ErrorTagList',
   r'/rest/catalogs/([^/]+)/([^/]+)/([^/]+)/pkgname-by-filename', 'PkgnameByFilename',
+  r'/rest/srv4/([0-9a-f]{32})/', 'RestSrv4Detail',
 )
 
 # render = web.template.render('templates/')
@@ -173,6 +174,19 @@
       raise web.notfound()
 
 
+class RestSrv4Detail(object):
+
+  def GET(self, md5_sum):
+    ConnectToDatabase()
+    try:
+      pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
+      mimetype, data_structure = pkg.GetRestRepr()
+      web.header('Content-type', mimetype)
+      return json.dumps(data_structure)
+    except sqlobject.main.SQLObjectNotFound, e:
+      raise web.notfound()
+
+
 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