Allow configuring additional database settings so we can use postgres.
authorDiane Trout <diane@caltech.edu>
Mon, 16 May 2011 22:02:45 +0000 (15:02 -0700)
committerDiane Trout <diane@caltech.edu>
Mon, 16 May 2011 22:02:45 +0000 (15:02 -0700)
Now instead of a couple of database settings in [frontend] in
the htsworkflow.ini file, frontend just points to a different
ini configuration block that contains the ability to set all
of the database configuration parameters.

htsworkflow/settings.py

index dadc47a1479511cf23e05ece9a802e9486b04752..68dfcf90916f10a6578a7fd467618896854ae63a 100644 (file)
@@ -27,6 +27,9 @@ The options understood by this module are (with their defaults):
 import ConfigParser
 import os
 import shlex
+import htsworkflow
+
+HTSWORKFLOW_ROOT = os.path.abspath(os.path.split(htsworkflow.__file__)[0])
 
 # make epydoc happy
 __docformat__ = "restructuredtext en"
@@ -53,7 +56,7 @@ options = ConfigParser.SafeConfigParser(
              'email_port': '25', 
              'database_engine': 'sqlite3',
              'database_name': 
-               os.path.abspath('../../fctracker.db'),
+                  os.path.join(HTSWORKFLOW_ROOT, '..', 'fctracker.db'),
              'time_zone': 'America/Los_Angeles',
              'default_pm': '5',
              'link_flowcell_storage_device_url': "http://localhost:8000/inventory/lts/link/",
@@ -102,15 +105,27 @@ else:
 NOTIFICATION_BCC = []
 options_to_list(options, NOTIFICATION_BCC, 'frontend', 'notification_bcc')
 
-# 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
-DATABASE_ENGINE = options.get('frontend', 'database_engine')
+database_section = options.get('frontend', 'database', 'database')
 
-# Or path to database file if using sqlite3.
-DATABASE_NAME = options.get('frontend', 'database_name' )
-DATABASE_USER = ''             # Not used with sqlite3.
-DATABASE_PASSWORD = ''         # Not used with sqlite3.
-DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
-DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+if not options.has_section(database_section):
+    raise ConfigParser.NoSectionError(
+        "No database=<database_section_name> defined")
+    
+# 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+DATABASE_ENGINE = options.get(database_section, 'engine')
+DATABASE_NAME = options.get(database_section, 'name')
+if options.has_option(database_section, 'user'):
+    DATABASE_USER = options.get(database_section, 'user')
+if options.has_option(database_section, 'host'):
+    DATABASE_HOST = options.get(database_section, 'host')
+if options.has_option(database_section, 'port'):
+    DATABASE_PORT = options.get(database_section, 'port')
+
+if options.has_option(database_section, 'password_file'):
+    password_file = options.get(database_section, 'password_file')
+    DATABASE_PASSWORD = open(password_file,'r').readline()
+elif options.has_option(database_section, 'password'):
+    DATABASE_PASSWORD = options.get(database_section, 'password')
 
 # Local time zone for this installation. Choices can be found here:
 # http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
@@ -132,7 +147,7 @@ USE_I18N = True
 
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = os.path.abspath(os.path.split(__file__)[0]) + '/static/'
+MEDIA_ROOT = os.path.join(HTSWORKFLOW_ROOT, 'frontend', 'static', '')
 
 # URL that handles the media served from MEDIA_ROOT.
 # Example: "http://media.lawrence.com"
@@ -171,8 +186,7 @@ TEMPLATE_DIRS = (
     # Don't forget to use absolute paths, not relative paths.
     '/usr/share/python-support/python-django/django/contrib/admin/templates',
     #'/usr/lib/pymodules/python2.6/django/contrib/admin/templates/',
-    os.path.join(os.path.split(__file__)[0],
-                 'frontend','templates'),
+    os.path.join(HTSWORKFLOW_ROOT, 'frontend','templates'),
 )
 
 INSTALLED_APPS = (