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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue May 14 18:45:07 CEST 2013


Revision: 21074
          http://gar.svn.sourceforge.net/gar/?rev=21074&view=rev
Author:   wahwah
Date:     2013-05-14 16:45:07 +0000 (Tue, 14 May 2013)
Log Message:
-----------
pkgdb-web: Return data for catalog generation

Just the data we need, no less, no more.

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

Added Paths:
-----------
    csw/mgar/gar/v2/lib/python/representations.py

Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py	2013-05-14 16:44:49 UTC (rev 21073)
+++ csw/mgar/gar/v2/lib/python/models.py	2013-05-14 16:45:07 UTC (rev 21074)
@@ -489,6 +489,39 @@
   ).orderBy('catalogname')
   return res
 
+
+def GetCatalogGenerationResult(sqo_osrel, sqo_arch, sqo_catrel):
+  """Get rows with catalog results.
+
+  CatalogEntry
+  catalogname version pkgname basename md5_sum size deps category i_deps
+  """
+  join = [
+      sqlbuilder.INNERJOINOn(None,
+        Srv4FileInCatalog,
+        Srv4FileInCatalog.q.srv4file==Srv4FileStats.q.id),
+      sqlbuilder.INNERJOINOn(None,
+        CatalogGenData,
+        Srv4FileStats.q.md5_sum==CatalogGenData.q.md5_sum),
+  ]
+  where = sqlbuilder.AND(
+      Srv4FileInCatalog.q.osrel==sqo_osrel,
+        Srv4FileInCatalog.q.arch==sqo_arch,
+        Srv4FileInCatalog.q.catrel==sqo_catrel,
+        Srv4FileStats.q.use_to_generate_catalogs==True,
+  )
+  select = sqlbuilder.Select(
+      ['catalogname', 'version_string', 'pkgname', 'basename',
+       'srv4_file_stats.md5_sum',
+       'size', 'deps', 'i_deps'],
+      where=where,
+      orderBy='catalogname',
+      join=join)
+  query = sqlobject.sqlhub.processConnection.sqlrepr(select)
+  rows = sqlobject.sqlhub.processConnection.queryAll(query)
+  return rows
+
+
 def GetSqoTriad(osrel, arch, catrel):
   sqo_osrel = OsRelease.selectBy(short_name=osrel).getOne()
   sqo_arch = Architecture.selectBy(name=arch).getOne()

Added: csw/mgar/gar/v2/lib/python/representations.py
===================================================================
--- csw/mgar/gar/v2/lib/python/representations.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/python/representations.py	2013-05-14 16:45:07 UTC (rev 21074)
@@ -0,0 +1,6 @@
+import collections
+
+# Full catalog entry, enough to write a line of a catalog file.
+CatalogEntry = collections.namedtuple(
+    'CatalogEntry', 'catalogname version pkgname basename'
+                    'md5_sum size deps category i_deps')

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2013-05-14 16:44:49 UTC (rev 21073)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2013-05-14 16:45:07 UTC (rev 21074)
@@ -17,6 +17,7 @@
 from lib.python import models
 from lib.python import configuration
 from lib.python import checkpkg_lib
+from lib.python import representations
 from lib.web import web_lib
 import datetime
 from sqlobject import sqlbuilder
@@ -43,6 +44,8 @@
       'PkgnameByFilename',
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames-and-paths-by-basename',
       'PkgnamesAndPathsByBasename',
+  r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/for-generation/',
+      'CatalogForGeneration',
   # 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',
@@ -505,6 +508,36 @@
     return cjson.encode(simple_data)
 
 
+class CatalogForGeneration(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
+    """
+    sqo_osrel, sqo_arch, sqo_catrel = models.GetSqoTriad(
+        osrel_name, arch_name, catrel_name)
+    rows = list(models.GetCatalogGenerationResult(sqo_osrel, sqo_arch, sqo_catrel))
+    def GenCatalogEntry(row):
+      entry = representations.CatalogEntry(
+          catalogname=row[0],
+          version=row[1],
+          pkgname=row[2],
+          basename=row[3],
+          md5_sum=row[4],
+          size=row[5],
+          deps="|".join([x[0] for x in cjson.decode(row[6])]),
+          category="none",
+          i_deps="|".join(cjson.decode(row[7])),
+      )
+      return entry
+    entries_list = [GenCatalogEntry(row) for row in rows]
+    response = cjson.encode([tuple(x) for x in entries_list])
+    web.header('Content-Length', str(len(response)))
+    return response
+
+
 web.webapi.internalerror = web.debugerror
 
 

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