blob: aec9dbb9251aadf81ddd3862406195aa6d6965b3 [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
Brad Bishop37a0e4d2017-12-04 01:01:44 -050063# Update as of django 1.8.16 release, the '*' is needed to allow us to connect while running
64# on hosts without explicitly setting the fqdn for the toaster server.
65# See https://docs.djangoproject.com/en/dev/ref/settings/ for info on ALLOWED_HOSTS
66# Previously this setting was not enforced if DEBUG was set but it is now.
67# The previous behavior was such that ALLOWED_HOSTS defaulted to ['localhost','127.0.0.1','::1']
68# and if you bound to 0.0.0.0:<port #> then accessing toaster as localhost or fqdn would both work.
69# To have that same behavior, with a fqdn explicitly enabled you would set
70# ALLOWED_HOSTS= ['localhost','127.0.0.1','::1','myserver.mycompany.com'] for
71# Django >= 1.8.16. By default, we are not enforcing this restriction in
72# DEBUG mode.
73if DEBUG is True:
74 # this will allow connection via localhost,hostname, or fqdn
75 ALLOWED_HOSTS = ['*']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076
77# Local time zone for this installation. Choices can be found here:
78# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
79# although not all choices may be available on all operating systems.
80# In a Windows environment this must be set to your system time zone.
81
82# Always use local computer's time zone, find
83import hashlib
84if 'TZ' in os.environ:
85 TIME_ZONE = os.environ['TZ']
86else:
87 # need to read the /etc/localtime file which is the libc standard
88 # and do a reverse-mapping to /usr/share/zoneinfo/;
89 # since the timezone may match any number of identical timezone definitions,
90
91 zonefilelist = {}
92 ZONEINFOPATH = '/usr/share/zoneinfo/'
93 for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
94 for fn in filenames:
95 filepath = os.path.join(dirpath, fn)
96 zonename = filepath.lstrip(ZONEINFOPATH).strip()
97 try:
98 import pytz
99 from pytz.exceptions import UnknownTimeZoneError
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 try:
101 if pytz.timezone(zonename) is not None:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600102 zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename
103 except UnknownTimeZoneError as ValueError:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 # we expect timezone failures here, just move over
105 pass
106 except ImportError:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600107 zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600109 TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110
111# Language code for this installation. All choices can be found here:
112# http://www.i18nguy.com/unicode/language-identifiers.html
113LANGUAGE_CODE = 'en-us'
114
115SITE_ID = 1
116
117# If you set this to False, Django will make some optimizations so as not
118# to load the internationalization machinery.
119USE_I18N = True
120
121# If you set this to False, Django will not format dates, numbers and
122# calendars according to the current locale.
123USE_L10N = True
124
125# If you set this to False, Django will not use timezone-aware datetimes.
126USE_TZ = True
127
128# Absolute filesystem path to the directory that will hold user-uploaded files.
129# Example: "/var/www/example.com/media/"
130MEDIA_ROOT = ''
131
132# URL that handles the media served from MEDIA_ROOT. Make sure to use a
133# trailing slash.
134# Examples: "http://example.com/media/", "http://media.example.com/"
135MEDIA_URL = ''
136
137# Absolute path to the directory static files should be collected to.
138# Don't put anything in this directory yourself; store your static files
139# in apps' "static/" subdirectories and in STATICFILES_DIRS.
140# Example: "/var/www/example.com/static/"
141STATIC_ROOT = ''
142
143# URL prefix for static files.
144# Example: "http://example.com/static/", "http://static.example.com/"
145STATIC_URL = '/static/'
146
147# Additional locations of static files
148STATICFILES_DIRS = (
149 # Put strings here, like "/home/html/static" or "C:/www/django/static".
150 # Always use forward slashes, even on Windows.
151 # Don't forget to use absolute paths, not relative paths.
152)
153
154# List of finder classes that know how to find static files in
155# various locations.
156STATICFILES_FINDERS = (
157 'django.contrib.staticfiles.finders.FileSystemFinder',
158 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
159# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
160)
161
162# Make this unique, and don't share it with anybody.
163SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT'
164
165# List of callables that know how to import templates from various sources.
166TEMPLATE_LOADERS = (
167 'django.template.loaders.filesystem.Loader',
168 'django.template.loaders.app_directories.Loader',
169# 'django.template.loaders.eggs.Loader',
170)
171
172MIDDLEWARE_CLASSES = (
173 'django.middleware.common.CommonMiddleware',
174 'django.contrib.sessions.middleware.SessionMiddleware',
175 'django.middleware.csrf.CsrfViewMiddleware',
176 'django.contrib.auth.middleware.AuthenticationMiddleware',
177 'django.contrib.messages.middleware.MessageMiddleware',
178 # Uncomment the next line for simple clickjacking protection:
179 # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
180)
181
182CACHES = {
183 # 'default': {
184 # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
185 # 'LOCATION': '127.0.0.1:11211',
186 # },
187 'default': {
188 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500189 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190 'TIMEOUT': 1,
191 }
192 }
193
194
195from os.path import dirname as DN
196SITE_ROOT=DN(DN(os.path.abspath(__file__)))
197
198import subprocess
199TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
200TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
201
202ROOT_URLCONF = 'toastermain.urls'
203
204# Python dotted path to the WSGI application used by Django's runserver.
205WSGI_APPLICATION = 'toastermain.wsgi.application'
206
207TEMPLATE_DIRS = (
208 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
209 # Always use forward slashes, even on Windows.
210 # Don't forget to use absolute paths, not relative paths.
211)
212
213TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth',
214 'django.core.context_processors.debug',
215 'django.core.context_processors.i18n',
216 'django.core.context_processors.media',
217 'django.core.context_processors.static',
218 'django.core.context_processors.tz',
219 'django.contrib.messages.context_processors.messages',
220 "django.core.context_processors.request",
221 'toastergui.views.managedcontextprocessor',
222 )
223
224INSTALLED_APPS = (
225 'django.contrib.auth',
226 'django.contrib.contenttypes',
227 'django.contrib.messages',
228 'django.contrib.sessions',
229 'django.contrib.admin',
230 'django.contrib.staticfiles',
231
232 # Uncomment the next line to enable admin documentation:
233 # 'django.contrib.admindocs',
234 'django.contrib.humanize',
235 'bldcollector',
236 'toastermain',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237)
238
239
240INTERNAL_IPS = ['127.0.0.1', '192.168.2.28']
241
242# Load django-fresh is TOASTER_DEVEL is set, and the module is available
243FRESH_ENABLED = False
244if os.environ.get('TOASTER_DEVEL', None) is not None:
245 try:
246 import fresh
247 MIDDLEWARE_CLASSES = ("fresh.middleware.FreshMiddleware",) + MIDDLEWARE_CLASSES
248 INSTALLED_APPS = INSTALLED_APPS + ('fresh',)
249 FRESH_ENABLED = True
250 except:
251 pass
252
253DEBUG_PANEL_ENABLED = False
254if os.environ.get('TOASTER_DEVEL', None) is not None:
255 try:
256 import debug_toolbar, debug_panel
257 MIDDLEWARE_CLASSES = ('debug_panel.middleware.DebugPanelMiddleware',) + MIDDLEWARE_CLASSES
258 #MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
259 INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',)
260 DEBUG_PANEL_ENABLED = True
261
262 # this cache backend will be used by django-debug-panel
263 CACHES['debug-panel'] = {
264 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
265 'LOCATION': '/var/tmp/debug-panel-cache',
266 'TIMEOUT': 300,
267 'OPTIONS': {
268 'MAX_ENTRIES': 200
269 }
270 }
271
272 except:
273 pass
274
275
276SOUTH_TESTS_MIGRATE = False
277
278
279# We automatically detect and install applications here if
280# they have a 'models.py' or 'views.py' file
281import os
282currentdir = os.path.dirname(__file__)
283for t in os.walk(os.path.dirname(currentdir)):
284 modulename = os.path.basename(t[0])
285 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600286 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287 continue
288
289 if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS:
290 INSTALLED_APPS = INSTALLED_APPS + (modulename,)
291
292# A sample logging configuration. The only tangible logging
293# performed by this configuration is to send an email to
294# the site admins on every HTTP 500 error when DEBUG=False.
295# See http://docs.djangoproject.com/en/dev/topics/logging for
296# more details on how to customize your logging configuration.
297LOGGING = {
298 'version': 1,
299 'disable_existing_loggers': False,
300 'filters': {
301 'require_debug_false': {
302 '()': 'django.utils.log.RequireDebugFalse'
303 }
304 },
305 'formatters': {
306 'datetime': {
307 'format': '%(asctime)s %(levelname)s %(message)s'
308 }
309 },
310 'handlers': {
311 'mail_admins': {
312 'level': 'ERROR',
313 'filters': ['require_debug_false'],
314 'class': 'django.utils.log.AdminEmailHandler'
315 },
316 'console': {
317 'level': 'DEBUG',
318 'class': 'logging.StreamHandler',
319 'formatter': 'datetime',
320 }
321 },
322 'loggers': {
323 'toaster' : {
324 'handlers': ['console'],
325 'level': 'DEBUG',
326 },
327 'django.request': {
328 'handlers': ['console'],
329 'level': 'WARN',
330 'propagate': True,
331 },
332 }
333}
334
335if DEBUG and SQL_DEBUG:
336 LOGGING['loggers']['django.db.backends'] = {
337 'level': 'DEBUG',
338 'handlers': ['console'],
339 }
340
341
342# If we're using sqlite, we need to tweak the performance a bit
343from django.db.backends.signals import connection_created
344def activate_synchronous_off(sender, connection, **kwargs):
345 if connection.vendor == 'sqlite':
346 cursor = connection.cursor()
347 cursor.execute('PRAGMA synchronous = 0;')
348connection_created.connect(activate_synchronous_off)
349#
350
351
352class InvalidString(str):
353 def __mod__(self, other):
354 from django.template.base import TemplateSyntaxError
355 raise TemplateSyntaxError(
356 "Undefined variable or unknown value for: \"%s\"" % other)
357
358TEMPLATE_STRING_IF_INVALID = InvalidString("%s")