diff roundup/backends/back_postgresql.py @ 2633:a9e1fff1e793

I thought I committed this last night. Ho hum. - This implements most of the rest of the new tracker config layout: - dbinit.py split between schema.py and initial_data.py - interfaces.py gone - tracker and detectors __init__.py gone - Added some missing functionality to backends: db_exists test and db_nuke. - Implemented configuration file options in postgresql backend. - Cleaned up tracker initialisation a lot.
author Richard Jones <richard@users.sourceforge.net>
date Tue, 27 Jul 2004 00:57:19 +0000
parents 091711fb2f8c
children f47ca4541770
line wrap: on
line diff
--- a/roundup/backends/back_postgresql.py	Tue Jul 27 00:45:49 2004 +0000
+++ b/roundup/backends/back_postgresql.py	Tue Jul 27 00:57:19 2004 +0000
@@ -14,15 +14,37 @@
 from roundup import hyperdb, date
 from roundup.backends import rdbms_common
 
+from roundup import configuration
+
+configuration.SETTINGS += (
+    ("postgresql", (
+        (configuration.Option, 'database', 'roundup'),
+        (configuration.NullableOption, 'host', 'localhost'),
+        (configuration.NullableOption, 'port', '5432'),
+        (configuration.NullableOption, 'user', 'roundup'),
+        (configuration.NullableOption, 'password', 'roundup'),
+    )),
+)
+
+def connection_dict(config):
+    d = {
+        'database': config.POSTGRESQL_DATABASE,
+    }
+    for name in 'host', 'port', 'password', 'user':
+        cvar = 'POSTGRESQL_'+name.upper()
+        if config[cvar] is not None:
+            d[name] = config[cvar]
+    return d
+
 def db_create(config):
     """Clear all database contents and drop database itself"""
-    command = 'CREATE DATABASE %s'%config.POSTGRESQL_DATABASE['database']
+    command = 'CREATE DATABASE %s'%config.POSTGRESQL_DATABASE
     config.logging.getLogger('hyperdb').info(command)
     db_command(config, command)
 
 def db_nuke(config, fail_ok=0):
     """Clear all database contents and drop database itself"""
-    command = 'DROP DATABASE %s'% config.POSTGRESQL_DATABASE['database']
+    command = 'DROP DATABASE %s'% config.POSTGRESQL_DATABASE
     config.logging.getLogger('hyperdb').info(command)
     db_command(config, command)
 
@@ -33,7 +55,7 @@
     '''Perform some sort of database-level command. Retry 10 times if we
     fail by conflicting with another user.
     '''
-    template1 = config.POSTGRESQL_DATABASE.copy()
+    template1 = connection_dict(config)
     template1['database'] = 'template1'
     
     try:
@@ -70,7 +92,7 @@
 
 def db_exists(config):
     """Check if database already exists"""
-    db = getattr(config, 'POSTGRESQL_DATABASE')
+    db = connection_dict(config)
     try:
         conn = psycopg.connect(**db)
         conn.close()
@@ -82,7 +104,7 @@
     arg = '%s'
 
     def sql_open_connection(self):
-        db = getattr(self.config, 'POSTGRESQL_DATABASE')
+        db = connection_dict(config)
         self.config.logging.getLogger('hyperdb').info('open database %r'%db)
         try:
             conn = psycopg.connect(**db)

Roundup Issue Tracker: http://roundup-tracker.org/