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