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