SF.net SVN: gar:[25426] csw/mgar/gar/v2/lib
cgrzemba at users.sourceforge.net
cgrzemba at users.sourceforge.net
Wed Dec 2 09:26:38 CET 2015
Revision: 25426
http://sourceforge.net/p/gar/code/25426
Author: cgrzemba
Date: 2015-12-02 08:26:37 +0000 (Wed, 02 Dec 2015)
Log Message:
-----------
add rest interface 'catnames-and-paths-by-basename'
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/checkpkg_lib.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 2015-12-02 07:20:21 UTC (rev 25425)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py 2015-12-02 08:26:37 UTC (rev 25426)
@@ -1039,7 +1039,56 @@
".AndReturn(%s)", repr(basename), pprint.pformat(pkgs))
return pkgs
+ def GetPathsAndCatalognamesByBasename(self, basename, osrel, arch, catrel):
+ """Retrieves catalogname+versionstr of packages that have certain files.
+ Args:
+ basename: u'libfoo.so.1'
+ osrel: u'5.9'
+ arch: 'sparc', 'x86'
+ catrel: 'stable'
+
+ Returns:
+ {"/opt/csw/lib": [("foo","1.0,REV=2015.10.10"), ("bar","2.0,REV=2001.09.01],
+ "/opt/csw/1/lib": [("foomore","1.0.1,REV=2015.10.10")]}
+ """
+ pkgs = {}
+ 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.basename==basename,
+ 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.path, m.Srv4FileStats.q.catalogname, m.Srv4FileStats.q.version_string],
+ where=where,
+ join=join))
+ rows = connection.queryAll(query)
+ pkgs = {}
+
+ for row in rows:
+ file_path, pkginst, version = row
+ pkgs.setdefault(file_path, []).append((pkginst,version))
+
+ logging.debug("self.error_mgr_mock.GetPathsAndCatalognamesByBasename(%s)"
+ ".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)
Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py 2015-12-02 07:20:21 UTC (rev 25425)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py 2015-12-02 08:26:37 UTC (rev 25426)
@@ -59,6 +59,8 @@
r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames-and-paths-by-basename',
'PkgnamesAndPathsByBasename', # with ?basename=...
r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/pkgnames-and-paths-by-basedir',
+ r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/catnames-and-paths-by-basename',
+ 'CatnamesAndPathsByBasename',
'PkgnamesAndPathsByBasedir', # with ?basedir=...
r'/rest/catalogs/([^/]+)/(sparc|i386)/(SunOS[^/]+)/for-generation/as-dicts/',
'CatalogForGenerationAsDicts',
@@ -461,7 +463,32 @@
web.header('Content-Length', str(len(response)))
return response
+class CatnamesAndPathsByBasename(object):
+ def GET(self, catrel, arch, osrel):
+ user_data = web.input()
+ try:
+ basename = user_data.basename
+ except AttributeError, e:
+ raise web.badrequest()
+ send_filename = (
+ '%s-%s-%s-%s-packages.txt'
+ % (catrel, arch, osrel, basename.replace('/', '-')))
+ db_catalog = checkpkg_lib.Catalog()
+ try:
+ data = db_catalog.GetPathsAndCatalognamesByBasename(
+ basename, osrel, arch, catrel)
+ except sqlobject.main.SQLObjectNotFound:
+ 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 PkgnamesAndPathsByBasedir(object):
def GET(self, catrel, arch, osrel):
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