source: trunk/sara_cmt/sara_cmt/settings.py @ 14155

Last change on this file since 14155 was 14155, checked in by ramonb, 12 years ago

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
File size: 6.1 KB
Line 
1
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)
43
44# Documentation of settings can be found on:
45#
46#   http://docs.djangoproject.com/en/dev/ref/settings/
47
48# Only set CLIENT_ONLY to False on the central CMT-server
49CLIENT_ONLY = True
50
51DEBUG = True
52
53ADMINS = (
54    ('Sil Westerveld', 'sil.westerveld@sara.nl'),
55    #('Your Name', 'your_email@domain.com'),
56)
57
58MANAGERS = ADMINS
59
60#####
61#
62# <AUTH AGAINST LDAP> (based on http://packages.python.org/django-auth-ldap/)
63#
64if not CLIENT_ONLY:
65    import ldap
66    from django_auth_ldap.config import LDAPSearch, PosixGroupType
67
68
69    # Baseline configuration.
70    AUTH_LDAP_SERVER_URI = "ldaps://ldap.cua.sara.nl"
71
72    # Set AUTH_LDAP_USER_DN_TEMPLATE to a template that will produce the
73    # authenticating user's DN directly. This template should have one
74    # placeholder, %(user)s.
75    AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=Users,dc=hpcv,dc=sara,dc=nl'
76
77    # Set up the basic group parameters.
78    AUTH_LDAP_GROUP_SEARCH = LDAPSearch('ou=Groups,dc=hpcv,dc=sara,dc=nl',
79        ldap.SCOPE_SUBTREE, '(objectClass=posixGroup)',
80    )
81    AUTH_LDAP_GROUP_TYPE = PosixGroupType()
82
83    ## Only users in this group can log in.
84    AUTH_LDAP_REQUIRE_GROUP = 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl'
85
86    # Populate the Django user from the LDAP directory.
87    AUTH_LDAP_USER_ATTR_MAP = {
88        'first_name': 'givenName',
89        'last_name': 'sn',
90        'email': 'mail',
91    }
92
93    AUTH_LDAP_USER_FLAGS_BY_GROUP = {
94        'is_active': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
95        'is_staff': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
96        'is_superuser': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
97    }
98
99    # This is the default, but I like to be explicit.
100    AUTH_LDAP_ALWAYS_UPDATE_USER = True
101
102    # Cache group memberships for an hour to minimize LDAP traffic
103    AUTH_LDAP_CACHE_GROUPS = True
104    AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
105
106    # Keep ModelBackend around for per-user permissions and maybe a local
107    # superuser.
108    AUTHENTICATION_BACKENDS = (
109        'django_auth_ldap.backend.LDAPBackend',
110        'django.contrib.auth.backends.ModelBackend',
111    )
112#
113# </AUTH AGAINST LDAP>
114#
115#####
116
117
118
119
120
121# Local time zone for this installation. Choices can be found here:
122# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
123# although not all choices may be available on all operating systems.
124# If running in a Windows environment this must be set to the same as your
125# system time zone.
126TIME_ZONE = 'Europe/Amsterdam'
127
128# Language code for this installation. All choices can be found here:
129# http://www.i18nguy.com/unicode/language-identifiers.html
130LANGUAGE_CODE = 'en-us'
131
132SITE_ID = 1
133
134# If you set this to False, Django will make some optimizations so as not
135# to load the internationalization machinery.
136USE_I18N = True
137
138# Absolute path to the directory that holds media.
139# Example: "/home/media/media.lawrence.com/"
140MEDIA_ROOT = ''
141
142# URL that handles the media served from MEDIA_ROOT. Make sure to use a
143# trailing slash if there is a path component (optional in other cases).
144# Examples: "http://media.lawrence.com", "http://example.com/media/"
145MEDIA_URL = ''
146
147# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
148# trailing slash.
149# Examples: "http://foo.com/media/", "/media/".
150ADMIN_MEDIA_PREFIX = '/admin_media/'
151
152# Make this unique, and don't share it with anybody.
153SECRET_KEY = 'uygv6wrel4o2%x8s4dk2%i6=dp!2bt32$0ne-%_7&j=ez*u$1b'
154
155# List of callables that know how to import templates from various sources.
156TEMPLATE_LOADERS = (
157    'django.template.loaders.filesystem.load_template_source',
158    'django.template.loaders.app_directories.load_template_source',
159    #'django.template.loaders.eggs.load_template_source',
160)
161
162MIDDLEWARE_CLASSES = (
163    'django.middleware.common.CommonMiddleware',
164    'django.contrib.sessions.middleware.SessionMiddleware',
165    'django.contrib.auth.middleware.AuthenticationMiddleware',
166    'debug_toolbar.middleware.DebugToolbarMiddleware',
167)
168
169ROOT_URLCONF = 'sara_cmt.urls'
170
171# Templates for the CMT command line interface.
172# (thus, the templates for our configfiles, etc)
173#TODO: think about a (better) way to make this dynamic:
174#TODO: get this out of the settings.py, since it should be in the client config
175import site
176CMT_TEMPLATES_DIR = '%s/etc/templates' % site.sys.prefix
177
178# Templates for the CMT web-frontend.
179TEMPLATE_DIRS = (
180    # Put strings here, like "/home/html/django_templates"
181    # or "C:/www/django/templates".
182    # Always use forward slashes, even on Windows.
183    # Don't forget to use absolute paths, not relative paths.
184    os.path.normpath(os.path.join(os.path.dirname(__file__), 'cluster/templates')),
185    CMT_TEMPLATES_DIR,
186)
187
188FIXTURE_DIRS = (
189    # A fixture is a collection of files that contain serialized contents of
190    # the database. (can be used for testing)
191    os.path.normpath(os.path.join(os.path.dirname(__file__), 'fixtures')),
192)
193
194
195INSTALLED_APPS = (
196    'django.contrib.auth',
197    'django.contrib.contenttypes',
198    'django.contrib.sessions',
199    'django.contrib.admin',
200    'django.contrib.databrowse',
201    'django.contrib.webdesign',
202    'sara_cmt.cluster',
203    'django_extensions',
204    'tagging',
205
206    # Only serverside:
207    #'debug_toolbar',
208    #'south',
209)
210
211# Append your IP to use the debug_toolbar
212INTERNAL_IPS = (
213    #'145.100.6.163', # saralt0115
214    '127.0.0.1',
215)
Note: See TracBrowser for help on using the repository browser.