Changeset 14155


Ignore:
Timestamp:
04/27/12 15:51:58 (12 years ago)
Author:
ramonb
Message:

etc/cmt.conf:

  • added database section and settings

sara_cmt/settings.py:

  • set database options based upon /etc/cmt/cmt.conf settings
  • removed settings_db
  • see #9
Location:
trunk/sara_cmt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sara_cmt/etc/cmt.conf

    r14151 r14155  
    1717LOGLEVEL    : INFO
    1818VERBOSE     : False
     19
     20[database]
     21ENGINE    : postgresql_psycopg2
     22NAME      : sara_cmt
     23USER      : cmt
     24#PASSWORD  : <set_me>
     25HOST      : cmt.osd.sara.nl
     26#PORT      : <optional>
     27TEST_NAME : sara_cmt_test
  • trunk/sara_cmt/sara_cmt/settings.py

    r14154 r14155  
    11
    2 import os
    3 
     2import os, sys, ConfigParser
     3
     4from socket import gethostbyname_ex
     5
     6config = ConfigParser.RawConfigParser()
     7config.read('/etc/cmt/cmt.conf')
     8
     9try:
     10        DATABASE_USER = config.get('database', 'USER')
     11        DATABASE_PASSWORD = config.get('database', 'PASSWORD')
     12        DATABASE_HOST = config.get('database', 'HOST')
     13        DATABASE_ENGINE = config.get('database', 'ENGINE')
     14        DATABASE_NAME = config.get('database', 'NAME')
     15
     16except ConfigParser.NoOptionError, details:
     17
     18        print 'Config file error: %s' %str(details)
     19        sys.exit(1)
     20
     21try: # Optional
     22        DATABASE_PORT = config.get('database', 'PORT')
     23        TEST_DATABASE_NAME = config.get('database', 'TEST_NAME')
     24
     25except ConfigParser.NoOptionError, details:
     26
     27        #whatever: optional arguments: unset
     28        try:
     29                del DATABASE_PORT
     30                del TEST_DATABASE_NAME
     31
     32        except NameError:
     33
     34                # care more
     35                pass
     36
     37try:
     38        gethostbyname_ex( DATABASE_HOST )
     39except socket.gaierror, details:
     40        print 'Unable to resolv database host: %s' %DATABASE_HOST
     41        print 'Exiting.'
     42        sys.exit(1)
    443
    544# Documentation of settings can be found on:
     
    1857
    1958MANAGERS = ADMINS
    20 
    21 
    22 # The database settings are imported, due to confidential data which should be
    23 # excluded from the SVN repository.
    24 try:
    25     from settings_db import *
    26 except ImportError:
    27     print '''\
    28 Settings for database are missing. Be sure to have `settings_db.py` with:
    29 
    30 DATABASES = {
    31     'default': {
    32         'ENGINE': '<engine>',
    33         'NAME': '<name>',
    34         'USER': '<user>',
    35         'PASSWORD': '<password>',
    36         'HOST': '<host>'
    37     }
    38 }
    39 
    40 See https://docs.djangoproject.com/en/1.2/ref/settings/#databases'''
    41     exit(1)
    42 
    43 
    4459
    4560#####
Note: See TracChangeset for help on using the changeset viewer.