[CalendarServer-changes] [14444] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 19 12:11:02 PST 2015
Revision: 14444
http://trac.calendarserver.org//changeset/14444
Author: wsanchez at apple.com
Date: 2015-02-19 12:11:01 -0800 (Thu, 19 Feb 2015)
Log Message:
-----------
DB code cleanup
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/database.py
CalendarServer/trunk/twistedcaldav/directory/test/test_proxyprincipaldb.py
CalendarServer/trunk/txdav/base/datastore/subpostgres.py
Modified: CalendarServer/trunk/twistedcaldav/database.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/database.py 2015-02-19 20:05:52 UTC (rev 14443)
+++ CalendarServer/trunk/twistedcaldav/database.py 2015-02-19 20:11:01 UTC (rev 14444)
@@ -17,10 +17,9 @@
import thread
try:
- import pgdb
+ import pgdb as postgres
except:
- pgdb = None
-# pgdb = None
+ postgres = None
from twisted.enterprise.adbapi import ConnectionPool
from twisted.internet.defer import inlineCallbacks, returnValue
@@ -571,7 +570,7 @@
# internal statements so we do not need to remap those
return sql
-if pgdb:
+if postgres:
class ADBAPIPostgreSQLMixin(object):
@@ -608,7 +607,7 @@
try:
yield self._db_execute(statement)
- except pgdb.DatabaseError:
+ except postgres.DatabaseError:
if not ifnotexists:
raise
@@ -638,7 +637,7 @@
try:
yield self._db_execute(statement)
- except pgdb.DatabaseError:
+ except postgres.DatabaseError:
if not ifnotexists:
raise
@@ -677,7 +676,7 @@
values ('TYPE', :1)
""", (self._db_type(),)
)
- except pgdb.DatabaseError:
+ except postgres.DatabaseError:
pass
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_proxyprincipaldb.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_proxyprincipaldb.py 2015-02-19 20:05:52 UTC (rev 14443)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_proxyprincipaldb.py 2015-02-19 20:11:01 UTC (rev 14444)
@@ -598,11 +598,11 @@
try:
- import pgdb
+ import pgdb as postgres
except ImportError:
ProxyPrincipalDBPostgreSQL.skip = True
else:
try:
- db = pgdb.connect(host="localhost", database="proxies")
+ db = postgres.connect(host="localhost", database="proxies")
except:
ProxyPrincipalDBPostgreSQL.skip = True
Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2015-02-19 20:05:52 UTC (rev 14443)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2015-02-19 20:11:01 UTC (rev 14444)
@@ -26,7 +26,7 @@
from hashlib import md5
from pipes import quote as shell_quote
-import pgdb
+import pgdb as postgres
from twisted.python.procutils import which
from twisted.internet.protocol import ProcessProtocol
@@ -254,6 +254,7 @@
self.port = None
self.listenAddresses = []
+ self.testMode = testMode
self.sharedBuffers = sharedBuffers if not testMode else 16
self.maxConnections = maxConnections if not testMode else 8
self.options = options
@@ -292,20 +293,20 @@
def activateDelayedShutdown(self):
"""
- Call this when starting database initialization code to protect against
- shutdown.
+ Call this when starting database initialization code to
+ protect against shutdown.
- Sets the delayedShutdown flag to True so that if reactor shutdown
- commences, the shutdown will be delayed until deactivateDelayedShutdown
- is called.
+ Sets the delayedShutdown flag to True so that if reactor
+ shutdown commences, the shutdown will be delayed until
+ deactivateDelayedShutdown is called.
"""
self.delayedShutdown = True
def deactivateDelayedShutdown(self):
"""
- Call this when database initialization code has completed so that the
- reactor can shutdown.
+ Call this when database initialization code has completed so
+ that the reactor can shutdown.
"""
self.delayedShutdown = False
if self.shutdownDeferred:
@@ -331,7 +332,7 @@
if self.port:
kwargs["host"] = "{}:{}".format(self.host, self.port)
- return DBAPIConnector(pgdb, postgresPreflight, dsn, **kwargs)
+ return DBAPIConnector(postgres, postgresPreflight, dsn, **kwargs)
def produceConnection(self, label="<unlabeled>", databaseName=None):
@@ -353,7 +354,7 @@
createDatabaseCursor.execute(
"drop database {}".format(self.databaseName)
)
- except pgdb.DatabaseError:
+ except postgres.DatabaseError:
pass
try:
@@ -420,9 +421,16 @@
"""
def createConnection():
- createDatabaseConn = self.produceConnection(
- "schema creation", "postgres"
- )
+ try:
+ createDatabaseConn = self.produceConnection(
+ "schema creation", "postgres"
+ )
+ except postgres.DatabaseError as e:
+ log.error(
+ "Unable to connect to database for schema creation: {error}",
+ error=e
+ )
+ raise
createDatabaseCursor = createDatabaseConn.cursor()
createDatabaseCursor.execute("commit")
return createDatabaseConn, createDatabaseCursor
@@ -465,6 +473,10 @@
options.append("-c log_rotation_age=1440")
options.append("-c logging_collector=on")
+ options.append("-c log_line_prefix=%t")
+ if self.testMode:
+ options.append("-c log_statement=all")
+
log.warn(
"Requesting postgres start via {cmd} {opts}",
cmd=pgCtl, opts=options
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150219/da4754d2/attachment.html>
More information about the calendarserver-changes
mailing list