From 2f593bd41e4d64d133acf675d4a8a6c694007cac Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Mon, 16 May 2011 15:02:45 -0700 Subject: [PATCH] Allow configuring additional database settings so we can use postgres. 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 | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/htsworkflow/settings.py b/htsworkflow/settings.py index dadc47a..68dfcf9 100644 --- a/htsworkflow/settings.py +++ b/htsworkflow/settings.py @@ -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= 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 = ( -- 2.30.2