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