blob: 3dfa2b2238999a97af7bc43633ec13e6f8b87e2e [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# BitBake Toaster Implementation
6#
7# Copyright (C) 2013 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22# Django settings for Toaster project.
23
Patrick Williamsc0f7c042017-02-23 20:41:17 -060024import os
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
26DEBUG = True
27TEMPLATE_DEBUG = DEBUG
28
29# Set to True to see the SQL queries in console
30SQL_DEBUG = False
31if os.environ.get("TOASTER_SQLDEBUG", None) is not None:
32 SQL_DEBUG = True
33
34
35ADMINS = (
36 # ('Your Name', 'your_email@example.com'),
37)
38
39MANAGERS = ADMINS
40
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''),
42 'build')
43
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044DATABASES = {
45 'default': {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046 # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
47 'ENGINE': 'django.db.backends.sqlite3',
48 # DB name or full path to database file if using sqlite3.
49 'NAME': "%s/toaster.sqlite" % TOASTER_SQLITE_DEFAULT_DIR,
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 'USER': '',
51 'PASSWORD': '',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 #'HOST': '127.0.0.1', # e.g. mysql server
53 #'PORT': '3306', # e.g. mysql port
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 }
55}
56
57# Needed when Using sqlite especially to add a longer timeout for waiting
58# for the database lock to be released
59# https://docs.djangoproject.com/en/1.6/ref/databases/#database-is-locked-errors
60if 'sqlite' in DATABASES['default']['ENGINE']:
61 DATABASES['default']['OPTIONS'] = { 'timeout': 20 }
62
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063# Hosts/domain names that are valid for this site; required if DEBUG is False
64# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
65ALLOWED_HOSTS = []
66
67# Local time zone for this installation. Choices can be found here:
68# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
69# although not all choices may be available on all operating systems.
70# In a Windows environment this must be set to your system time zone.
71
72# Always use local computer's time zone, find
73import hashlib
74if 'TZ' in os.environ:
75 TIME_ZONE = os.environ['TZ']
76else:
77 # need to read the /etc/localtime file which is the libc standard
78 # and do a reverse-mapping to /usr/share/zoneinfo/;
79 # since the timezone may match any number of identical timezone definitions,
80
81 zonefilelist = {}
82 ZONEINFOPATH = '/usr/share/zoneinfo/'
83 for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
84 for fn in filenames:
85 filepath = os.path.join(dirpath, fn)
86 zonename = filepath.lstrip(ZONEINFOPATH).strip()
87 try:
88 import pytz
89 from pytz.exceptions import UnknownTimeZoneError
Patrick Williamsc124f4f2015-09-15 14:41:29 -050090 try:
91 if pytz.timezone(zonename) is not None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060092 zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename
93 except UnknownTimeZoneError as ValueError:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094 # we expect timezone failures here, just move over
95 pass
96 except ImportError:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060097 zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098
Patrick Williamsc0f7c042017-02-23 20:41:17 -060099 TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100
101# Language code for this installation. All choices can be found here:
102# http://www.i18nguy.com/unicode/language-identifiers.html
103LANGUAGE_CODE = 'en-us'
104
105SITE_ID = 1
106
107# If you set this to False, Django will make some optimizations so as not
108# to load the internationalization machinery.
109USE_I18N = True
110
111# If you set this to False, Django will not format dates, numbers and
112# calendars according to the current locale.
113USE_L10N = True
114
115# If you set this to False, Django will not use timezone-aware datetimes.
116USE_TZ = True
117
118# Absolute filesystem path to the directory that will hold user-uploaded files.
119# Example: "/var/www/example.com/media/"
120MEDIA_ROOT = ''
121
122# URL that handles the media served from MEDIA_ROOT. Make sure to use a
123# trailing slash.
124# Examples: "http://example.com/media/", "http://media.example.com/"
125MEDIA_URL = ''
126
127# Absolute path to the directory static files should be collected to.
128# Don't put anything in this directory yourself; store your static files
129# in apps' "static/" subdirectories and in STATICFILES_DIRS.
130# Example: "/var/www/example.com/static/"
131STATIC_ROOT = ''
132
133# URL prefix for static files.
134# Example: "http://example.com/static/", "http://static.example.com/"
135STATIC_URL = '/static/'
136
137# Additional locations of static files
138STATICFILES_DIRS = (
139 # Put strings here, like "/home/html/static" or "C:/www/django/static".
140 # Always use forward slashes, even on Windows.
141 # Don't forget to use absolute paths, not relative paths.
142)
143
144# List of finder classes that know how to find static files in
145# various locations.
146STATICFILES_FINDERS = (
147 'django.contrib.staticfiles.finders.FileSystemFinder',
148 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
149# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
150)
151
152# Make this unique, and don't share it with anybody.
153SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT'
154
155# List of callables that know how to import templates from various sources.
156TEMPLATE_LOADERS = (
157 'django.template.loaders.filesystem.Loader',
158 'django.template.loaders.app_directories.Loader',
159# 'django.template.loaders.eggs.Loader',
160)
161
162MIDDLEWARE_CLASSES = (
163 'django.middleware.common.CommonMiddleware',
164 'django.contrib.sessions.middleware.SessionMiddleware',
165 'django.middleware.csrf.CsrfViewMiddleware',
166 'django.contrib.auth.middleware.AuthenticationMiddleware',
167 'django.contrib.messages.middleware.MessageMiddleware',
168 # Uncomment the next line for simple clickjacking protection:
169 # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
170)
171
172CACHES = {
173 # 'default': {
174 # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
175 # 'LOCATION': '127.0.0.1:11211',
176 # },
177 'default': {
178 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500179 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 'TIMEOUT': 1,
181 }
182 }
183
184
185from os.path import dirname as DN
186SITE_ROOT=DN(DN(os.path.abspath(__file__)))
187
188import subprocess
189TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
190TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
191
192ROOT_URLCONF = 'toastermain.urls'
193
194# Python dotted path to the WSGI application used by Django's runserver.
195WSGI_APPLICATION = 'toastermain.wsgi.application'
196
197TEMPLATE_DIRS = (
198 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
199 # Always use forward slashes, even on Windows.
200 # Don't forget to use absolute paths, not relative paths.
201)
202
203TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth',
204 'django.core.context_processors.debug',
205 'django.core.context_processors.i18n',
206 'django.core.context_processors.media',
207 'django.core.context_processors.static',
208 'django.core.context_processors.tz',
209 'django.contrib.messages.context_processors.messages',
210 "django.core.context_processors.request",
211 'toastergui.views.managedcontextprocessor',
212 )
213
214INSTALLED_APPS = (
215 'django.contrib.auth',
216 'django.contrib.contenttypes',
217 'django.contrib.messages',
218 'django.contrib.sessions',
219 'django.contrib.admin',
220 'django.contrib.staticfiles',
221
222 # Uncomment the next line to enable admin documentation:
223 # 'django.contrib.admindocs',
224 'django.contrib.humanize',
225 'bldcollector',
226 'toastermain',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227)
228
229
230INTERNAL_IPS = ['127.0.0.1', '192.168.2.28']
231
232# Load django-fresh is TOASTER_DEVEL is set, and the module is available
233FRESH_ENABLED = False
234if os.environ.get('TOASTER_DEVEL', None) is not None:
235 try:
236 import fresh
237 MIDDLEWARE_CLASSES = ("fresh.middleware.FreshMiddleware",) + MIDDLEWARE_CLASSES
238 INSTALLED_APPS = INSTALLED_APPS + ('fresh',)
239 FRESH_ENABLED = True
240 except:
241 pass
242
243DEBUG_PANEL_ENABLED = False
244if os.environ.get('TOASTER_DEVEL', None) is not None:
245 try:
246 import debug_toolbar, debug_panel
247 MIDDLEWARE_CLASSES = ('debug_panel.middleware.DebugPanelMiddleware',) + MIDDLEWARE_CLASSES
248 #MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
249 INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',)
250 DEBUG_PANEL_ENABLED = True
251
252 # this cache backend will be used by django-debug-panel
253 CACHES['debug-panel'] = {
254 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
255 'LOCATION': '/var/tmp/debug-panel-cache',
256 'TIMEOUT': 300,
257 'OPTIONS': {
258 'MAX_ENTRIES': 200
259 }
260 }
261
262 except:
263 pass
264
265
266SOUTH_TESTS_MIGRATE = False
267
268
269# We automatically detect and install applications here if
270# they have a 'models.py' or 'views.py' file
271import os
272currentdir = os.path.dirname(__file__)
273for t in os.walk(os.path.dirname(currentdir)):
274 modulename = os.path.basename(t[0])
275 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600276 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277 continue
278
279 if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS:
280 INSTALLED_APPS = INSTALLED_APPS + (modulename,)
281
282# A sample logging configuration. The only tangible logging
283# performed by this configuration is to send an email to
284# the site admins on every HTTP 500 error when DEBUG=False.
285# See http://docs.djangoproject.com/en/dev/topics/logging for
286# more details on how to customize your logging configuration.
287LOGGING = {
288 'version': 1,
289 'disable_existing_loggers': False,
290 'filters': {
291 'require_debug_false': {
292 '()': 'django.utils.log.RequireDebugFalse'
293 }
294 },
295 'formatters': {
296 'datetime': {
297 'format': '%(asctime)s %(levelname)s %(message)s'
298 }
299 },
300 'handlers': {
301 'mail_admins': {
302 'level': 'ERROR',
303 'filters': ['require_debug_false'],
304 'class': 'django.utils.log.AdminEmailHandler'
305 },
306 'console': {
307 'level': 'DEBUG',
308 'class': 'logging.StreamHandler',
309 'formatter': 'datetime',
310 }
311 },
312 'loggers': {
313 'toaster' : {
314 'handlers': ['console'],
315 'level': 'DEBUG',
316 },
317 'django.request': {
318 'handlers': ['console'],
319 'level': 'WARN',
320 'propagate': True,
321 },
322 }
323}
324
325if DEBUG and SQL_DEBUG:
326 LOGGING['loggers']['django.db.backends'] = {
327 'level': 'DEBUG',
328 'handlers': ['console'],
329 }
330
331
332# If we're using sqlite, we need to tweak the performance a bit
333from django.db.backends.signals import connection_created
334def activate_synchronous_off(sender, connection, **kwargs):
335 if connection.vendor == 'sqlite':
336 cursor = connection.cursor()
337 cursor.execute('PRAGMA synchronous = 0;')
338connection_created.connect(activate_synchronous_off)
339#
340
341
342class InvalidString(str):
343 def __mod__(self, other):
344 from django.template.base import TemplateSyntaxError
345 raise TemplateSyntaxError(
346 "Undefined variable or unknown value for: \"%s\"" % other)
347
348TEMPLATE_STRING_IF_INVALID = InvalidString("%s")