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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Mar 25 19:46:13 CEST 2012


Revision: 17547
          http://gar.svn.sourceforge.net/gar/?rev=17547&view=rev
Author:   wahwah
Date:     2012-03-25 17:46:13 +0000 (Sun, 25 Mar 2012)
Log Message:
-----------
pkgdb-web: Connect to the database in the entry pt

Don't establish the db connection during a query, do that in the entry
point instead.

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	2012-03-25 17:45:42 UTC (rev 17546)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2012-03-25 17:46:13 UTC (rev 17547)
@@ -87,7 +87,6 @@
 
 class Srv4List(object):
   def GET(self):
-    ConnectToDatabase()
     pkgs = models.Srv4FileStats.select().orderBy('-mtime')[:30]
     now = datetime.datetime.now()
     def Ago(timedelta):
@@ -101,7 +100,6 @@
 
 class Srv4Detail(object):
   def GET(self, md5_sum):
-    ConnectToDatabase()
     try:
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       overrides = pkg.GetOverridesResult()
@@ -131,7 +129,6 @@
 
 class Catalogname(object):
   def GET(self, catalogname):
-    ConnectToDatabase()
     try:
       pkgs = models.Srv4FileStats.selectBy(
           catalogname=catalogname,
@@ -143,7 +140,6 @@
 
 class CatalognameList(object):
   def GET(self):
-    ConnectToDatabase()
     try:
       connection = models.Srv4FileStats._connection
       rows = connection.queryAll(connection.sqlrepr(
@@ -161,7 +157,6 @@
 
 class Srv4DetailFiles(object):
   def GET(self, md5_sum):
-    ConnectToDatabase()
     srv4 = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
     files = models.CswFile.selectBy(srv4_file=srv4)
     return render.Srv4DetailFiles(srv4, files)
@@ -169,7 +164,6 @@
 
 class CatalogList(object):
   def GET(self):
-    ConnectToDatabase()
     archs = models.Architecture.select()
     osrels = models.OsRelease.select()
     catrels = models.CatalogRelease.select()
@@ -188,7 +182,6 @@
 
 class CatalogDetail(object):
   def GET(self, catrel_name, arch_name, osrel_name):
-    ConnectToDatabase()
     cat_name = " ".join((catrel_name, arch_name, osrel_name))
     sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad(
         osrel_name, arch_name, catrel_name)
@@ -198,7 +191,6 @@
 
 class MaintainerList(object):
   def GET(self):
-    ConnectToDatabase()
     maintainers = models.Maintainer.select().orderBy('email')
     names = [tuple(x.email.split("@") + [x]) for x in maintainers]
     return render.MaintainerList(names)
@@ -206,7 +198,6 @@
 
 class MaintainerDetail(object):
   def GET(self, id):
-    ConnectToDatabase()
     maintainer = models.Maintainer.selectBy(id=id).getOne()
     pkgs = models.Srv4FileStats.select(
         sqlobject.AND(
@@ -219,14 +210,12 @@
 
 class RestMaintainerDetail(object):
   def GET(self, id):
-    ConnectToDatabase()
     maintainer = models.Maintainer.selectBy(id=id).getOne()
     return json.dumps(maintainer.GetRestRepr())
 
 
 class MaintainerCheckpkgReport(object):
   def GET(self, id):
-    ConnectToDatabase()
     maintainer = models.Maintainer.selectBy(id=id).getOne()
     pkgs = models.Srv4FileStats.select(
         sqlobject.AND(
@@ -249,7 +238,6 @@
 
 class ErrorTagDetail(object):
   def GET(self, tag_name):
-    ConnectToDatabase()
     join = [
         sqlbuilder.INNERJOINOn(None,
           models.Srv4FileStats,
@@ -267,7 +255,6 @@
 
 class ErrorTagList(object):
   def GET(self):
-    ConnectToDatabase()
     connection = models.CheckpkgErrorTag._connection
     rows = connection.queryAll(connection.sqlrepr(
       sqlbuilder.Select(
@@ -279,7 +266,6 @@
 
 class Catalogs(object):
   def GET(self, catrel_name, arch_name, osrel_name):
-    ConnectToDatabase()
     sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad(
         osrel_name, arch_name, catrel_name)
     pkgs = list(models.GetCatPackagesResult(sqo_osrel, sqo_arch, sqo_catrel))
@@ -294,7 +280,6 @@
 
 class PkgnameByFilename(object):
   def GET(self, catrel, arch, osrel):
-    ConnectToDatabase()
     user_data = web.input()
     filename = user_data.filename
     send_filename = (
@@ -314,7 +299,6 @@
 
 class PkgnamesAndPathsByBasename(object):
   def GET(self, catrel, arch, osrel):
-    ConnectToDatabase()
     user_data = web.input()
     basename = user_data.basename
     send_filename = (
@@ -337,7 +321,6 @@
 class RestSrv4Detail(object):
 
   def GET(self, md5_sum):
-    ConnectToDatabase()
     try:
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       mimetype, data_structure = pkg.GetRestRepr()
@@ -351,7 +334,6 @@
 class RestSrv4DetailFiles(object):
 
   def GET(self, md5_sum):
-    ConnectToDatabase()
     try:
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       files = models.CswFile.selectBy(srv4_file=pkg)
@@ -372,7 +354,6 @@
 class RestSrv4FullStats(object):
 
   def GET(self, md5_sum):
-    ConnectToDatabase()
     try:
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       data_structure = pkg.GetStatsStruct()
@@ -452,10 +433,15 @@
 
 web.webapi.internalerror = web.debugerror
 
-app = web.application(urls, globals())
-main = app.wsgifunc()
-application = app.wsgifunc()
 
+def app_wrapper():
+  ConnectToDatabase()
+  app = web.application(urls, globals())
+  logging.basicConfig(level=logging.DEBUG)
+  return app.wsgifunc()
 
+application = app_wrapper()
+
+
 if __name__ == "__main__":
   app.run()

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