[CalendarServer-changes] [6617] CalendarServer/trunk/calendarserver/tap/caldav.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 11 10:59:30 PST 2010


Revision: 6617
          http://trac.macosforge.org/projects/calendarserver/changeset/6617
Author:   glyph at apple.com
Date:     2010-11-11 10:59:28 -0800 (Thu, 11 Nov 2010)
Log Message:
-----------
Make scoping clearer so Pyflakes can warn me about it.  Fix an issue where postgresUID/postgresGID wasn't set when we're not spawning postgres.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2010-11-11 18:19:51 UTC (rev 6616)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2010-11-11 18:59:28 UTC (rev 6617)
@@ -869,18 +869,6 @@
         @rtype: L{IService}
         """
         if config.UseDatabase:
-            def subServiceFactory(connectionFactory):
-                ms = ErrorLoggingMultiService()
-                cp = ConnectionPool(connectionFactory)
-                cp.setServiceParent(ms)
-                store = storeFromConfig(config, cp.connection)
-                mainService = createMainService(cp, store)
-                maybeUpgradeSvc = UpgradeToDatabaseService.wrapService(
-                    CachingFilePath(config.DocumentRoot), mainService,
-                    store, uid=postgresUID, gid=postgresGID
-                )
-                maybeUpgradeSvc.setServiceParent(ms)
-                return ms
             if config.DBType == '':
                 # Spawn our own database as an inferior process, then connect
                 # to it.
@@ -891,13 +879,15 @@
                     postgresUID = None
                     postgresGID = None
                 pgserv = pgServiceFromConfig(
-                    config, subServiceFactory, postgresUID, postgresGID
+                    config,
+                    self.subServiceFactoryFactory(postgresUID, postgresGID),
+                    postgresUID, postgresGID
                 )
                 return pgserv
             elif config.DBType == 'postgres':
                 # Connect to a postgres database that is already running.
                 import pgdb
-                return subServiceFactory(
+                return self.subServiceFactoryFactory(createMainService)(
                     DBAPIConnector(
                         pgdb, postgresPreflight, config.DSN).connect)
             else:
@@ -907,6 +897,23 @@
             return createMainService(None, store)
 
 
+    def subServiceFactoryFactory(self, createMainService,
+                                 postgresUID=None, postgresGID=None):
+        def subServiceFactory(connectionFactory):
+            ms = ErrorLoggingMultiService()
+            cp = ConnectionPool(connectionFactory)
+            cp.setServiceParent(ms)
+            store = storeFromConfig(config, cp.connection)
+            mainService = createMainService(cp, store)
+            maybeUpgradeSvc = UpgradeToDatabaseService.wrapService(
+                CachingFilePath(config.DocumentRoot), mainService,
+                store, uid=postgresUID, gid=postgresGID
+            )
+            maybeUpgradeSvc.setServiceParent(ms)
+            return ms
+        return subServiceFactory
+
+
     def makeService_Combined(self, options):
         """
         Create a master service to coordinate a multi-process configuration,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101111/704d706e/attachment.html>


More information about the calendarserver-changes mailing list