Scheduler: adding/removing resources enforce warnings and recount number of unconfigu...
[myslice.git] / myslice / settings.py
1 import os.path
2 import logging
3
4 logger = logging.getLogger('myslice')
5
6 # ROOT
7 try:
8     ROOT = os.path.realpath(os.path.dirname(__file__) + '/..')
9 except:
10     import traceback
11     traceback.print_exc()
12
13
14 from myslice.configengine import ConfigEngine
15
16 config = ConfigEngine()
17
18 import myslice.components as components
19
20
21
22 # import djcelery
23 # djcelery.setup_loader()
24
25 ### detect if we're in a build environment
26 try:
27     import manifold
28     building=False
29 except:
30     building=True
31
32
33
34 # DEBUG
35 if config.myslice.debug :
36     DEBUG = True
37 else :
38     DEBUG = False
39
40 # theme
41 if config.myslice.theme :
42     theme = config.myslice.theme
43 else :
44     theme = None
45
46 # HTTPROOT
47 if config.myslice.httproot :
48     HTTPROOT = config.myslice.httproot
49 else :
50     HTTPROOT = ROOT
51
52 # DATAROOT
53 if config.myslice.httproot :
54     DATAROOT = config.myslice.dataroot
55 else :
56     DATAROOT = ROOT
57
58
59 # dec 2013 - we currently have 2 auxiliary subdirs with various utilities
60 # that we do not wish to package 
61 # * sandbox is for plugin developers
62 # * sample is for various test views
63 # for each of these, if we find a directory of that name under ROOT, it then gets
64 # inserted in INSTALLED_APPS and its urls get included (see urls.py)
65 auxiliaries = [ 'sandbox', 'sample', ]
66
67 ####################
68 ADMINS = (
69     # ('your_name', 'your_email@test.com'),
70 )
71
72 MANAGERS = ADMINS
73
74 # Mail configuration
75 #DEFAULT_FROM_EMAIL = "root@theseus.ipv6.lip6.fr"
76 #EMAIL_HOST_PASSWORD = "mypassword"
77
78 EMAIL_HOST = "localhost"
79 EMAIL_PORT = 25
80 EMAIL_USE_TLS = False
81
82 # use the email for debugging purpose
83 # turn on debugging: 
84 # python -m smtpd -n -c DebuggingServer localhost:1025
85
86 #if DEBUG:
87 #    EMAIL_HOST = 'localhost'
88 #    EMAIL_PORT = 1025
89 #    EMAIL_HOST_USER = ''
90 #    EMAIL_HOST_PASSWORD = ''
91 #    EMAIL_USE_TLS = False
92 #    DEFAULT_FROM_EMAIL = 'testing@example.com'
93
94 if config.database.engine : 
95     DATABASES = {
96         'default': {
97             'ENGINE'    : 'django.db.backends.%s' % config.database.engine,
98             'USER'      : config.database.user or '',
99             'PASSWORD'  : config.database.password or '',
100             'HOST'      : config.database.host or '',
101             'PORT'      : config.database.port or '',
102         }
103     }
104     if config.database.engine == 'sqlite3' :
105         DATABASES['default']['NAME'] = os.path.join(DATAROOT,'%s.sqlite3' % config.database.name)
106     else :
107         DATABASES['default']['NAME'] = config.database.name
108 else :
109     # default database is sqlite
110     DATABASES = {
111         'default': {
112             'ENGINE'    : 'django.db.backends.sqlite3',
113             'NAME'      : os.path.join(DATAROOT,'myslice.sqlite3'),
114             'USER'      : '',
115             'PASSWORD'  : '',
116             'HOST'      : '',
117             'PORT'      : '',
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 # In a Windows environment this must be set to your system time zone.
125 TIME_ZONE = 'Europe/Paris'
126
127 # Language code for this installation. All choices can be found here:
128 # http://www.i18nguy.com/unicode/language-identifiers.html
129 LANGUAGE_CODE = 'en-us'
130
131 SITE_ID = 1
132
133 # If you set this to False, Django will make some optimizations so as not
134 # to load the internationalization machinery.
135 USE_I18N = True
136
137 # If you set this to False, Django will not format dates, numbers and
138 # calendars according to the current locale.
139 USE_L10N = True
140
141 # If you set this to False, Django will not use timezone-aware datetimes.
142 USE_TZ = True
143
144 # Absolute filesystem path to the directory that will hold user-uploaded files.
145 # Example: "/home/media/media.lawrence.com/media/"
146 MEDIA_ROOT = ''
147
148 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
149 # trailing slash.
150 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
151 MEDIA_URL = ''
152
153 # Absolute path to the directory static files should be collected to.
154 # Don't put anything in this directory yourself; store your static files
155 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
156 # Example: "/home/media/media.lawrence.com/static/"
157 STATIC_ROOT = os.path.join(HTTPROOT,'static')
158
159 # URL prefix for static files.
160 # Example: "http://media.lawrence.com/static/"
161 STATIC_URL = '/static/'
162
163 # Additional locations of static files
164 STATICFILES_DIRS = (
165     # Put strings here, like "/home/html/static" or "C:/www/django/static".
166     # Always use forward slashes, even on Windows.
167     # Don't forget to use absolute paths, not relative paths.
168     # Thierry : we do not need to detail the contents 
169     # of our 'apps' since they're mentioned in INSTALLED_APPS
170 )
171
172 # Needed by PluginFinder
173 PLUGIN_DIR = os.path.join(ROOT,'plugins')
174 # ThirdPartyFinder
175 THIRDPARTY_DIR = os.path.join(ROOT, 'third-party')
176
177 # List of finder classes that know how to find static files in
178 # various locations.
179 STATICFILES_FINDERS = (
180 # Thierry : no need for this one    
181 #    'django.contrib.staticfiles.finders.FileSystemFinder',
182     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
183     'unfold.collectstatic.PluginFinder',
184     'unfold.collectstatic.ThirdPartyFinder',
185 ###    'django.contrib.staticfiles.finders.DefaultStorageFinder',
186 )
187
188 #TEMPLATE_CONTEXT_PROCESSORS = (
189 #    'django.contrib.auth.context_processors.auth',
190 #    'django.core.context_processors.debug',
191 #    'django.core.context_processors.i18n',
192 #    'django.core.context_processors.media',
193 #    'django.core.context_processors.static',
194 #    'django.core.context_processors.request',
195 #    'django.contrib.messages.context_processors.messages',
196 #)
197
198 # Make this unique, and don't share it with anybody.
199 SECRET_KEY = 't%n(3h)&r^n8(+8)(sp29t^$c2#t(m3)e2!02l8w1#36tl#t27'
200
201 # List of callables that know how to import templates from various sources.
202 TEMPLATE_LOADERS = (
203     'django.template.loaders.filesystem.Loader',
204     'django.template.loaders.app_directories.Loader',
205 #     'django.template.loaders.eggs.Loader',
206 )
207
208 MIDDLEWARE_CLASSES = (
209     'django.middleware.common.CommonMiddleware',
210     'django.contrib.sessions.middleware.SessionMiddleware',
211     'django.middleware.csrf.CsrfViewMiddleware',
212     'django.contrib.auth.middleware.AuthenticationMiddleware',
213     'django.contrib.messages.middleware.MessageMiddleware',
214     # Uncomment the next line for simple clickjacking protection:
215     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
216 )
217
218 ROOT_URLCONF = 'myslice.urls'
219
220 # Python dotted path to the WSGI application used by Django's runserver.
221 WSGI_APPLICATION = 'unfold.wsgi.application'
222
223 TEMPLATE_DIRS = []
224 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
225 # Always use forward slashes, even on Windows.
226 # Don't forget to use absolute paths, not relative paths.
227 if theme is not None:
228     TEMPLATE_DIRS.append( os.path.join(HTTPROOT,"portal/templates", theme) )
229 TEMPLATE_DIRS.append( os.path.join(HTTPROOT,"portal/templates") )
230 TEMPLATE_DIRS.append( os.path.join(HTTPROOT,"templates") )
231
232 INSTALLED_APPS = [ 
233     'django.contrib.auth',
234     'django.contrib.contenttypes',
235     'django.contrib.sessions',
236     'django.contrib.sites',
237     'django.contrib.messages',
238     'django.contrib.staticfiles',
239     # handling the {% insert %} and {% container %} tags
240     # see details in devel/django-insert-above-1.0-4
241     'insert_above',
242     # our django project
243     'myslice',
244     # the core of the UI
245     'auth', 
246     'manifoldapi',
247     'unfold',
248     # plugins
249     'plugins',
250     # views - more or less stable 
251     'ui',
252     # managing database migrations
253     'south', 
254     # Uncomment the next line to enable the admin:
255      'django.contrib.admin',
256         # FORGE Plugin app
257 #       'djcelery',
258     # Uncomment the next line to enable admin documentation:
259     # 'django.contrib.admindocs',
260     'portal',
261 ]
262 # this app won't load in a build environment
263 if not building: INSTALLED_APPS.append ('rest')
264
265 for component in components.list() :
266     INSTALLED_APPS.append(component)
267
268 BROKER_URL = "amqp://myslice:myslice@localhost:5672/myslice"
269
270 for aux in auxiliaries:
271     if os.path.isdir(os.path.join(ROOT,aux)): 
272         print("Using devel auxiliary",aux)
273         INSTALLED_APPS.append(aux)
274
275 ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
276
277 # A sample logging configuration. The only tangible logging
278 # performed by this configuration is to send an email to
279 # the site admins on every HTTP 500 error when DEBUG=False.
280 # See http://docs.djangoproject.com/en/dev/topics/logging for
281 # more details on how to customize your logging configuration.
282 LOGGING = {
283     'version': 1,
284     'disable_existing_loggers': False,
285     'filters': {
286         'require_debug_false': {
287             '()': 'django.utils.log.RequireDebugFalse'
288         }
289     },
290     'handlers': {
291         'mail_admins': {
292             'level': 'ERROR',
293             'filters': ['require_debug_false'],
294             'class': 'django.utils.log.AdminEmailHandler',
295         }
296     },
297     'loggers': {
298         'django.request': {
299             'handlers': ['mail_admins'],
300             'level': 'ERROR',
301             'propagate': True,
302         },
303     }
304 }
305 LOGGING = {
306     'version': 1,
307     'disable_existing_loggers': True,
308     'formatters': {
309         'verbose': {
310             'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
311         },
312         'simple': {
313             'format': '%(levelname)s %(message)s'
314         },
315     },
316     'filters': {
317         
318     },
319     'handlers': {
320         'null': {
321             'level': 'DEBUG',
322             'class': 'django.utils.log.NullHandler',
323         },
324         'debug':{
325             'level': 'DEBUG',
326             'class': 'logging.StreamHandler',
327             'formatter': 'simple'
328         }
329     },
330     'loggers': {
331         'myslice': {
332             'handlers': ['debug'],
333             'propagate': True,
334             'level': 'DEBUG',
335         }
336     }
337 }
338
339 AUTHENTICATION_BACKENDS = ('auth.manifoldbackend.ManifoldBackend',
340                            'django.contrib.auth.backends.ModelBackend')
341
342 ### the view to redirect malformed (i.e. with a wrong CSRF) incoming requests
343 # without this setting django will return a 403 forbidden error, which is fine
344 # if you need to see the error message then use this setting
345 CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure'
346
347 #################### for insert_above
348 #IA_JS_FORMAT = "<script type='text/javascript' src='{URL}' />"
349 # put stuff under static/
350 # IA_MEDIA_PREFIX = '/code/'
351
352 ####SLA#####
353
354 SLA_MANAGER_URL = "http://157.193.215.125:4001/sla-collector/sla"
355 #SLA_MANAGER_URL = "http://172.24.76.28:8000/sla"
356 SLA_MANAGER_USER = "portal"
357 SLA_MANAGER_PASSWORD = "password"