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

Last change on this file since 14165 was 14165, checked in by ramonb, 12 years ago
  • perhaps this Hint is not the best of ideas
  • removed hint
  • see #9
File size: 8.2 KB
Line 
1
2import os, os.path, sys, ConfigParser, site, string, time
3
4from socket import gethostbyname_ex
5
6# Path's customizable through virtualenv
7sample_configfile = '%s/etc/cmt/cmt.conf.sample' % site.sys.prefix
8configfile = '%s/etc/cmt/cmt.conf' % site.sys.prefix
9
10def count_configlines( filename ):
11
12        line_count      = 0
13        cfg_fp          = open( filename )
14
15        for line in cfg_fp.readlines():
16
17                line = line.strip()
18
19                if len( line ) == 0:
20                        continue
21
22                # RB: ConfigParser considers lines starting with # or ; as comments
23                if line[0] == '#' or line[0] == ';':
24                        continue
25
26                line_count += 1
27
28        cfg_fp.close()
29
30        return line_count
31
32if not os.path.exists( configfile ):
33
34        print 'Unable to find config file: %s' %configfile
35
36        if os.path.exists( sample_configfile ):
37
38                print ''
39                print 'Please modify the sample config file: %s to reflect your settings' %sample_configfile
40                print 'and then rename it to: %s' %configfile
41
42        else:
43
44                print ''
45                print 'Also no sample config file was found: %s' %sample_configfile
46                print 'Something is terribly wrong here ;)'
47
48        print ''
49        print 'Fatal: Giving up and exiting now..'
50
51        sys.exit(1)
52
53# We are still here: both configfile AND sample_configfile found
54if os.path.exists( sample_configfile ):
55
56        # Is the sample configfile newer?
57        if os.path.getmtime( sample_configfile ) > os.path.getmtime( configfile ):
58
59                # Well this is weird, but not fatal
60                print 'Warning: sample config file(%s) is newer than original config(%s)' %(configfile, sample_configfile)
61
62                # Does the sample config file contain more options?
63                if count_configlines( sample_configfile ) > count_configlines( configfile ):
64
65                        print 'Warning: sample config file contains MORE OPTIONS than original config!'
66                        print ''
67                        print 'This happens for example if you upgraded CMT and the new release incorporates new configuration options!'
68                        print ''
69                        print 'Please update your original config(%s) to incorporate the new config options from sample config(%s)' %( configfile, sample_configfile )
70                        print ''
71
72                # Give them some time to think about warnings and generally annoy them just enough to fix it
73                time.sleep(2)
74
75                # Moving right along; print empty line for cosmetic reasons
76                print ''
77
78config = ConfigParser.RawConfigParser()
79config.read( configfile )
80
81try:
82        DATABASE_USER           = config.get('database', 'USER')
83        DATABASE_PASSWORD       = config.get('database', 'PASSWORD')
84        DATABASE_HOST           = config.get('database', 'HOST')
85        DATABASE_ENGINE         = config.get('database', 'ENGINE')
86        DATABASE_NAME           = config.get('database', 'NAME')
87
88except (ConfigParser.NoOptionError, ConfigParser.NoSectionError), details:
89
90        print 'Config file error: %s' %str(details)
91        print ''
92        print 'Giving up and exiting now..'
93        sys.exit(1)
94
95try: # Optional
96        DATABASE_PORT = config.get('database', 'PORT')
97
98except ConfigParser.NoOptionError, details:
99
100        pass
101
102try: # Optional
103        TEST_DATABASE_NAME = config.get('database', 'TEST_NAME')
104
105except ConfigParser.NoOptionError, details:
106
107        pass
108
109try:
110        gethostbyname_ex( DATABASE_HOST )
111
112except socket.gaierror, details:
113
114        print 'Unable to resolve database host: %s' %DATABASE_HOST
115        print ''
116        print 'Giving up and exiting now..'
117        sys.exit(1)
118
119# Documentation of settings can be found on:
120#
121#   http://docs.djangoproject.com/en/dev/ref/settings/
122
123# Only set CLIENT_ONLY to False on the central CMT-server
124CLIENT_ONLY = True
125
126DEBUG = True
127
128ADMINS = (
129    ('Sil Westerveld', 'sil.westerveld@sara.nl'),
130    #('Your Name', 'your_email@domain.com'),
131)
132
133MANAGERS = ADMINS
134
135#####
136#
137# <AUTH AGAINST LDAP> (based on http://packages.python.org/django-auth-ldap/)
138#
139if not CLIENT_ONLY:
140    import ldap
141    from django_auth_ldap.config import LDAPSearch, PosixGroupType
142
143
144    # Baseline configuration.
145    AUTH_LDAP_SERVER_URI = "ldaps://ldap.cua.sara.nl"
146
147    # Set AUTH_LDAP_USER_DN_TEMPLATE to a template that will produce the
148    # authenticating user's DN directly. This template should have one
149    # placeholder, %(user)s.
150    AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=Users,dc=hpcv,dc=sara,dc=nl'
151
152    # Set up the basic group parameters.
153    AUTH_LDAP_GROUP_SEARCH = LDAPSearch('ou=Groups,dc=hpcv,dc=sara,dc=nl',
154        ldap.SCOPE_SUBTREE, '(objectClass=posixGroup)',
155    )
156    AUTH_LDAP_GROUP_TYPE = PosixGroupType()
157
158    ## Only users in this group can log in.
159    AUTH_LDAP_REQUIRE_GROUP = 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl'
160
161    # Populate the Django user from the LDAP directory.
162    AUTH_LDAP_USER_ATTR_MAP = {
163        'first_name': 'givenName',
164        'last_name': 'sn',
165        'email': 'mail',
166    }
167
168    AUTH_LDAP_USER_FLAGS_BY_GROUP = {
169        'is_active': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
170        'is_staff': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
171        'is_superuser': 'cn=cmt,ou=Groups,dc=hpcv,dc=sara,dc=nl',
172    }
173
174    # This is the default, but I like to be explicit.
175    AUTH_LDAP_ALWAYS_UPDATE_USER = True
176
177    # Cache group memberships for an hour to minimize LDAP traffic
178    AUTH_LDAP_CACHE_GROUPS = True
179    AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
180
181    # Keep ModelBackend around for per-user permissions and maybe a local
182    # superuser.
183    AUTHENTICATION_BACKENDS = (
184        'django_auth_ldap.backend.LDAPBackend',
185        'django.contrib.auth.backends.ModelBackend',
186    )
187#
188# </AUTH AGAINST LDAP>
189#
190#####
191
192
193
194
195
196# Local time zone for this installation. Choices can be found here:
197# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
198# although not all choices may be available on all operating systems.
199# If running in a Windows environment this must be set to the same as your
200# system time zone.
201TIME_ZONE = 'Europe/Amsterdam'
202
203# Language code for this installation. All choices can be found here:
204# http://www.i18nguy.com/unicode/language-identifiers.html
205LANGUAGE_CODE = 'en-us'
206
207SITE_ID = 1
208
209# If you set this to False, Django will make some optimizations so as not
210# to load the internationalization machinery.
211USE_I18N = True
212
213# Absolute path to the directory that holds media.
214# Example: "/home/media/media.lawrence.com/"
215MEDIA_ROOT = ''
216
217# URL that handles the media served from MEDIA_ROOT. Make sure to use a
218# trailing slash if there is a path component (optional in other cases).
219# Examples: "http://media.lawrence.com", "http://example.com/media/"
220MEDIA_URL = ''
221
222# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
223# trailing slash.
224# Examples: "http://foo.com/media/", "/media/".
225ADMIN_MEDIA_PREFIX = '/admin_media/'
226
227# Make this unique, and don't share it with anybody.
228SECRET_KEY = 'uygv6wrel4o2%x8s4dk2%i6=dp!2bt32$0ne-%_7&j=ez*u$1b'
229
230# List of callables that know how to import templates from various sources.
231TEMPLATE_LOADERS = (
232    'django.template.loaders.filesystem.load_template_source',
233    'django.template.loaders.app_directories.load_template_source',
234    #'django.template.loaders.eggs.load_template_source',
235)
236
237MIDDLEWARE_CLASSES = (
238    'django.middleware.common.CommonMiddleware',
239    'django.contrib.sessions.middleware.SessionMiddleware',
240    'django.contrib.auth.middleware.AuthenticationMiddleware',
241    'debug_toolbar.middleware.DebugToolbarMiddleware',
242)
243
244ROOT_URLCONF = 'sara_cmt.urls'
245
246# Templates for the CMT command line interface.
247# (thus, the templates for our configfiles, etc)
248#TODO: think about a (better) way to make this dynamic:
249#TODO: get this out of the settings.py, since it should be in the client config
250CMT_TEMPLATES_DIR = '%s/etc/cmt/templates' % site.sys.prefix
251
252# Templates for the CMT web-frontend.
253TEMPLATE_DIRS = (
254    # Put strings here, like "/home/html/django_templates"
255    # or "C:/www/django/templates".
256    # Always use forward slashes, even on Windows.
257    # Don't forget to use absolute paths, not relative paths.
258    os.path.normpath(os.path.join(os.path.dirname(__file__), 'cluster/templates')),
259    CMT_TEMPLATES_DIR,
260)
261
262FIXTURE_DIRS = (
263    # A fixture is a collection of files that contain serialized contents of
264    # the database. (can be used for testing)
265    os.path.normpath(os.path.join(os.path.dirname(__file__), 'fixtures')),
266)
267
268
269INSTALLED_APPS = (
270    'django.contrib.auth',
271    'django.contrib.contenttypes',
272    'django.contrib.sessions',
273    'django.contrib.admin',
274    'django.contrib.databrowse',
275    'django.contrib.webdesign',
276    'sara_cmt.cluster',
277    'django_extensions',
278    'tagging',
279
280    # Only serverside:
281    #'debug_toolbar',
282    #'south',
283)
284
285# Append your IP to use the debug_toolbar
286INTERNAL_IPS = (
287    #'145.100.6.163', # saralt0115
288    '127.0.0.1',
289)
Note: See TracBrowser for help on using the repository browser.