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