Allow configuring additional database settings so we can use postgres.
[htsworkflow.git] / htsworkflow / settings.py
index 0f2d4da46c0eb93821addb9387c15960e1769cf7..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/",
@@ -86,6 +89,8 @@ options_to_list(options, ADMINS, 'frontend', 'admins')
 MANAGERS = []
 options_to_list(options, MANAGERS, 'frontend', 'managers')
 
+DEFAULT_PM=int(options.get('frontend', 'default_pm'))
+
 AUTHENTICATION_BACKENDS = ( 
   'htsworkflow.frontend.samples.auth_backend.HTSUserModelBackend', )
 CUSTOM_USER_MODEL = 'samples.HTSUser' 
@@ -100,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
@@ -130,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"
@@ -169,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],
-                 'htsworkflow', 'frontend','templates'),
+    os.path.join(HTSWORKFLOW_ROOT, 'frontend','templates'),
 )
 
 INSTALLED_APPS = (
@@ -216,4 +232,3 @@ BCPRINTER_PRINTER1_PORT = int(options.get('bcprinter', 'printer1_port'))
 BCPRINTER_PRINTER2_HOST = options.get('bcprinter', 'printer2_host')
 BCPRINTER_PRINTER2_PORT = int(options.get('bcprinter', 'printer2_port'))
 
-DEFAULT_PM=int(options.get('frontend', 'default_pm'))