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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Fri Mar 14 02:58:04 CET 2014


Revision: 23210
          http://sourceforge.net/p/gar/code/23210
Author:   wahwah
Date:     2014-03-14 01:58:02 +0000 (Fri, 14 Mar 2014)
Log Message:
-----------
pkgdb-web: Catalog generation data as dicts

It turns out that returning lists of different values make it annoying to
deserialize in typed languages. Here's an endpoint returning the same data as
a list of dicts.

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	2014-03-13 10:07:41 UTC (rev 23209)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2014-03-14 01:58:02 UTC (rev 23210)
@@ -56,6 +56,8 @@
       'PkgnamesAndPathsByBasename',  # with ?basename=...
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames-and-paths-by-basedir',
       'PkgnamesAndPathsByBasedir',  # with ?basedir=...
+  r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/for-generation/as-dicts/',
+      'CatalogForGenerationAsDicts',
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/for-generation/',
       'CatalogForGeneration',
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/timing/',
@@ -658,6 +660,56 @@
     return response
 
 
+def GetCatalogEntries(catrel_name, arch_name, osrel_name):
+  """Returns a list of CatalogEntry tuples."""
+  try:
+    sqo_osrel, sqo_arch, sqo_catrel = models.GetSqoTriad(
+        osrel_name, arch_name, catrel_name)
+  except sqlobject.main.SQLObjectNotFound:
+    raise web.notfound()
+  rows = list(models.GetCatalogGenerationResult(sqo_osrel, sqo_arch, sqo_catrel))
+  def FormatList(lst):
+    if lst:
+      return '|'.join(lst)
+    else:
+      return 'none'
+  def GenCatalogEntry(row):
+    i_deps = cjson.decode(row[7])
+    i_deps_str = FormatList(i_deps)
+    deps_with_desc = cjson.decode(row[6])
+    deps = [x[0] for x in deps_with_desc if x[0].startswith('CSW')]
+    deps_str = FormatList(deps)
+    entry = representations.CatalogEntry(
+        catalogname=row[0],  # 0
+        version=row[1],      # 1
+        pkgname=row[2],      # 2
+        basename=row[3],     # 3
+        md5_sum=row[4],      # 4
+        size=str(row[5]),    # 5
+        deps=deps_str,       # 6
+        category="none",     # 7
+        i_deps=i_deps_str,   # 8
+        desc=row[8],         # 9
+    )
+    return entry
+  entries_list = [GenCatalogEntry(row) for row in rows]
+  return entries_list
+
+
+class CatalogForGenerationAsDicts(object):
+
+  def GET(self, catrel_name, arch_name, osrel_name):
+    """A list of tuples, aligning with the catalog format.
+
+    catalogname version_string pkgname
+    basename md5_sum size deps category i_deps
+    """
+    entries_list = GetCatalogEntries(catrel_name, arch_name, osrel_name)
+    response = cjson.encode([x._asdict() for x in entries_list])
+    web.header('Content-Length', str(len(response)))
+    return response
+
+
 class CatalogForGeneration(object):
 
   def GET(self, catrel_name, arch_name, osrel_name):
@@ -666,37 +718,7 @@
     catalogname version_string pkgname
     basename md5_sum size deps category i_deps
     """
-    try:
-      sqo_osrel, sqo_arch, sqo_catrel = models.GetSqoTriad(
-          osrel_name, arch_name, catrel_name)
-    except sqlobject.main.SQLObjectNotFound:
-      raise web.notfound()
-    rows = list(models.GetCatalogGenerationResult(sqo_osrel, sqo_arch, sqo_catrel))
-    def FormatList(lst):
-      if lst:
-        return '|'.join(lst)
-      else:
-        return 'none'
-    def GenCatalogEntry(row):
-      i_deps = cjson.decode(row[7])
-      i_deps_str = FormatList(i_deps)
-      deps_with_desc = cjson.decode(row[6])
-      deps = [x[0] for x in deps_with_desc if x[0].startswith('CSW')]
-      deps_str = FormatList(deps)
-      entry = representations.CatalogEntry(
-          catalogname=row[0],  # 0
-          version=row[1],      # 1
-          pkgname=row[2],      # 2
-          basename=row[3],     # 3
-          md5_sum=row[4],      # 4
-          size=str(row[5]),    # 5
-          deps=deps_str,       # 6
-          category="none",     # 7
-          i_deps=i_deps_str,   # 8
-          desc=row[8],         # 9
-      )
-      return entry
-    entries_list = [GenCatalogEntry(row) for row in rows]
+    entries_list = GetCatalogEntries(catrel_name, arch_name, osrel_name)
     response = cjson.encode([tuple(x) for x in entries_list])
     web.header('Content-Length', str(len(response)))
     return response

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