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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Aug 11 16:08:13 CEST 2013


Revision: 21707
          http://gar.svn.sourceforge.net/gar/?rev=21707&view=rev
Author:   wahwah
Date:     2013-08-11 14:08:09 +0000 (Sun, 11 Aug 2013)
Log Message:
-----------
pkgdb-web: Query package by base directory

Find files and packages keeping files in a certain directory.

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

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2013-08-10 19:34:45 UTC (rev 21706)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2013-08-11 14:08:09 UTC (rev 21707)
@@ -997,6 +997,39 @@
                   ".AndReturn(%s)", repr(basename), pprint.pformat(pkgs))
     return pkgs
 
+  def GetPathsAndPkgnamesByBasedir(self, basedir, osrel, arch, catrel):
+    sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad(
+        osrel, arch, catrel)
+    connection = m.CswFile._connection
+    join = [
+        sqlbuilder.INNERJOINOn(None,
+          m.Pkginst,
+          m.CswFile.q.pkginst==m.Pkginst.q.id),
+        sqlbuilder.INNERJOINOn(None,
+          m.Srv4FileStats,
+          m.CswFile.q.srv4_file==m.Srv4FileStats.q.id),
+        sqlbuilder.INNERJOINOn(None,
+          m.Srv4FileInCatalog,
+          m.Srv4FileStats.q.id==m.Srv4FileInCatalog.q.srv4file),
+    ]
+    where = sqlobject.AND(
+        m.CswFile.q.path==basedir,
+        m.Srv4FileInCatalog.q.osrel==sqo_osrel,
+        m.Srv4FileInCatalog.q.arch==sqo_arch,
+        m.Srv4FileInCatalog.q.catrel==sqo_catrel,
+    )
+    query = connection.sqlrepr(
+        sqlbuilder.Select(
+          [m.CswFile.q.basename, m.Pkginst.q.pkgname],
+          where=where,
+          join=join))
+    rows = connection.queryAll(query)
+    pkgs = {}
+    for row in rows:
+    	basename, pkginst = row
+    	pkgs.setdefault(pkginst, []).append(basename)
+    return pkgs
+
   def GetPkgByPath(self, full_file_path, osrel, arch, catrel):
     """Returns a list of packages."""
     # Memoization for performance

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2013-08-10 19:34:45 UTC (rev 21706)
+++ csw/mgar/gar/v2/lib/python/rest.py	2013-08-11 14:08:09 UTC (rev 21707)
@@ -253,7 +253,16 @@
     data = urllib2.urlopen(url).read()
     return cjson.decode(data)
 
+  def GetBasenamesByCatalogAndDir(self, catrel, arch, osrel, basedir):
+    url = (
+        self.rest_url
+        + self.PKGDB_APP
+        + "/catalogs/%s/%s/%s/pkgnames-and-paths-by-basedir?basedir=%s"
+           % (catrel, arch, osrel, urlencode(basedir)))
+    data = urllib2.urlopen(url).read()
+    return cjson.decode(data)
 
+
 class CachedPkgstats(object):
   """Class responsible for holding and caching package stats.
 

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2013-08-10 19:34:45 UTC (rev 21706)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2013-08-11 14:08:09 UTC (rev 21707)
@@ -43,7 +43,9 @@
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgname-by-filename',
       'PkgnameByFilename',
   r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames-and-paths-by-basename',
-      'PkgnamesAndPathsByBasename',
+      '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/',
       'CatalogForGeneration',
   # Query by catalog release, arch, OS release and catalogname
@@ -361,6 +363,32 @@
     return cjson.encode(data)
 
 
+class PkgnamesAndPathsByBasedir(object):
+  def GET(self, catrel, arch, osrel):
+    user_data = web.input()
+    try:
+      basedir = user_data.basedir
+    except AttributeError, e:
+      raise web.badrequest()
+    send_filename = (
+        '%s-%s-%s-%s-packages.txt'
+        % (catrel, arch, osrel, basedir.replace('/', '-')))
+    db_catalog = checkpkg_lib.Catalog()
+    try:
+      data = db_catalog.GetPathsAndPkgnamesByBasedir(
+          basedir, osrel, arch, catrel)
+    except sqlobject.main.SQLObjectNotFound, e:
+      raise web.notfound()
+    web.header(
+        'Content-type',
+        'application/x-vnd.opencsw.pkg;type=pkgname-list')
+    web.header('Content-Disposition',
+               'attachment; filename=%s' % send_filename)
+    response = cjson.encode(data)
+    web.header('Content-Length', str(len(response)))
+    return response
+
+
 class RestSrv4Detail(object):
 
   def GET(self, md5_sum):

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