[CalendarServer-changes] [14498] CalendarServer/trunk/txdav/base/datastore/subpostgres.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 3 16:29:34 PST 2015


Revision: 14498
          http://trac.calendarserver.org//changeset/14498
Author:   wsanchez at apple.com
Date:     2015-03-03 16:29:34 -0800 (Tue, 03 Mar 2015)
Log Message:
-----------
Make _connectorFor() a dispatcher based on the dbm module name.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/base/datastore/subpostgres.py

Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py	2015-03-03 21:48:54 UTC (rev 14497)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py	2015-03-04 00:29:34 UTC (rev 14498)
@@ -163,7 +163,7 @@
         """
         The process is over, fire the Deferred with the output.
         """
-        self.deferred.callback(''.join(self.output))
+        self.deferred.callback("".join(self.output))
 
 
 
@@ -317,16 +317,20 @@
         if databaseName is None:
             databaseName = self.databaseName
 
+        m = getattr(self, "_connectorFor_{}".format(postgres.__name__), None)
+        if m is None:
+            raise InternalDataStoreError("Unknown Postgres DBM module: {}".format(postgres))
+
+        return m(databaseName)
+
+
+    def _connectorFor_pgdb(self, databaseName):
+        dsn = "{}:dbname={}".format(self.host, databaseName)
+
         if self.spawnedDBUser:
-            dsn = "{}:dbname={}:{}".format(
-                self.host, databaseName, self.spawnedDBUser
-            )
+            dsn = "{}:{}".format(dsn, self.spawnedDBUser)
         elif self.uid is not None:
-            dsn = "{}:dbname={}:{}".format(
-                self.host, databaseName, pwd.getpwuid(self.uid).pw_name
-            )
-        else:
-            dsn = "{}:dbname={}".format(self.host, databaseName)
+            dsn = "{}:{}".format(dsn, pwd.getpwuid(self.uid).pw_name)
 
         kwargs = {}
         if self.port:
@@ -546,7 +550,10 @@
             We can't start postgres or connect to a running instance.  Shut
             down.
             """
-            log.failure("Can't start or connect to postgres", f)
+            log.critical(
+                "Can't start or connect to postgres: {failure.value}",
+                failure=f
+            )
             self.deactivateDelayedShutdown()
             self.reactor.stop()
 
@@ -601,7 +608,7 @@
             def doCreate(result):
                 if result.find("FATAL:") != -1:
                     log.error(result)
-                    raise RuntimeError(
+                    raise InternalDataStoreError(
                         "Unable to initialize postgres database: {}"
                         .format(result)
                     )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150303/399a2c31/attachment-0001.html>


More information about the calendarserver-changes mailing list