blob: 3c123593660bb8cd3a239bb1fe766636f63d9e38 [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
Andrew Geissler20137392023-10-12 04:59:14 -060012from pathlib import Path
13from toastermain.logs import LOGGING_SETTINGS
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
15DEBUG = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17# Set to True to see the SQL queries in console
18SQL_DEBUG = False
19if os.environ.get("TOASTER_SQLDEBUG", None) is not None:
20 SQL_DEBUG = True
21
22
23ADMINS = (
24 # ('Your Name', 'your_email@example.com'),
25)
26
27MANAGERS = ADMINS
28
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029TOASTER_SQLITE_DEFAULT_DIR = os.environ.get('TOASTER_DIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031DATABASES = {
32 'default': {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033 # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
34 'ENGINE': 'django.db.backends.sqlite3',
35 # DB name or full path to database file if using sqlite3.
36 'NAME': "%s/toaster.sqlite" % TOASTER_SQLITE_DEFAULT_DIR,
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037 'USER': '',
38 'PASSWORD': '',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060039 #'HOST': '127.0.0.1', # e.g. mysql server
40 #'PORT': '3306', # e.g. mysql port
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 }
42}
43
Andrew Geissler9aee5002022-03-30 16:27:02 +000044# New in Django 3.2
45DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
46
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047# Needed when Using sqlite especially to add a longer timeout for waiting
48# for the database lock to be released
49# https://docs.djangoproject.com/en/1.6/ref/databases/#database-is-locked-errors
50if 'sqlite' in DATABASES['default']['ENGINE']:
51 DATABASES['default']['OPTIONS'] = { 'timeout': 20 }
52
Brad Bishop37a0e4d2017-12-04 01:01:44 -050053# Update as of django 1.8.16 release, the '*' is needed to allow us to connect while running
54# on hosts without explicitly setting the fqdn for the toaster server.
55# See https://docs.djangoproject.com/en/dev/ref/settings/ for info on ALLOWED_HOSTS
56# Previously this setting was not enforced if DEBUG was set but it is now.
57# The previous behavior was such that ALLOWED_HOSTS defaulted to ['localhost','127.0.0.1','::1']
58# and if you bound to 0.0.0.0:<port #> then accessing toaster as localhost or fqdn would both work.
59# To have that same behavior, with a fqdn explicitly enabled you would set
60# ALLOWED_HOSTS= ['localhost','127.0.0.1','::1','myserver.mycompany.com'] for
61# Django >= 1.8.16. By default, we are not enforcing this restriction in
62# DEBUG mode.
63if DEBUG is True:
64 # this will allow connection via localhost,hostname, or fqdn
65 ALLOWED_HOSTS = ['*']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
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
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111# If you set this to False, Django will not use timezone-aware datetimes.
112USE_TZ = True
113
114# Absolute filesystem path to the directory that will hold user-uploaded files.
115# Example: "/var/www/example.com/media/"
116MEDIA_ROOT = ''
117
118# URL that handles the media served from MEDIA_ROOT. Make sure to use a
119# trailing slash.
120# Examples: "http://example.com/media/", "http://media.example.com/"
121MEDIA_URL = ''
122
123# Absolute path to the directory static files should be collected to.
124# Don't put anything in this directory yourself; store your static files
125# in apps' "static/" subdirectories and in STATICFILES_DIRS.
126# Example: "/var/www/example.com/static/"
127STATIC_ROOT = ''
128
129# URL prefix for static files.
130# Example: "http://example.com/static/", "http://static.example.com/"
131STATIC_URL = '/static/'
132
133# Additional locations of static files
134STATICFILES_DIRS = (
135 # Put strings here, like "/home/html/static" or "C:/www/django/static".
136 # Always use forward slashes, even on Windows.
137 # Don't forget to use absolute paths, not relative paths.
138)
139
140# List of finder classes that know how to find static files in
141# various locations.
142STATICFILES_FINDERS = (
143 'django.contrib.staticfiles.finders.FileSystemFinder',
144 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
145# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
146)
147
148# Make this unique, and don't share it with anybody.
149SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT'
150
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600151TMPDIR = os.environ.get('TOASTER_DJANGO_TMPDIR', '/tmp')
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 ],
Andrew Geissler20137392023-10-12 04:59:14 -0600189 # https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled
190 # Generally, string_if_invalid should only be enabled in order to debug
191 # a specific template problem, then cleared once debugging is complete.
192 # If you assign a value other than '' to string_if_invalid,
193 # you will experience rendering problems with these templates and sites.
194 # 'string_if_invalid': InvalidString("%s"),
195 'string_if_invalid': "",
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500196 'debug': DEBUG,
197 },
198 },
199]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200
Andrew Geissler82c905d2020-04-13 13:39:40 -0500201MIDDLEWARE = [
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 'django.middleware.common.CommonMiddleware',
203 'django.contrib.sessions.middleware.SessionMiddleware',
204 'django.middleware.csrf.CsrfViewMiddleware',
205 'django.contrib.auth.middleware.AuthenticationMiddleware',
206 'django.contrib.messages.middleware.MessageMiddleware',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500207 'django.contrib.auth.middleware.AuthenticationMiddleware',
208 'django.contrib.messages.middleware.MessageMiddleware',
209 'django.contrib.sessions.middleware.SessionMiddleware',
210]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211
212CACHES = {
213 # 'default': {
214 # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
215 # 'LOCATION': '127.0.0.1:11211',
216 # },
217 'default': {
218 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600219 'LOCATION': '%s/toaster_cache_%d' % (TMPDIR, os.getuid()),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 'TIMEOUT': 1,
221 }
222 }
223
224
225from os.path import dirname as DN
226SITE_ROOT=DN(DN(os.path.abspath(__file__)))
227
228import subprocess
229TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
230TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
231
232ROOT_URLCONF = 'toastermain.urls'
233
234# Python dotted path to the WSGI application used by Django's runserver.
235WSGI_APPLICATION = 'toastermain.wsgi.application'
236
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237
238INSTALLED_APPS = (
239 'django.contrib.auth',
240 'django.contrib.contenttypes',
241 'django.contrib.messages',
242 'django.contrib.sessions',
243 'django.contrib.admin',
244 'django.contrib.staticfiles',
245
246 # Uncomment the next line to enable admin documentation:
247 # 'django.contrib.admindocs',
248 'django.contrib.humanize',
249 'bldcollector',
250 'toastermain',
Andrew Geissler20137392023-10-12 04:59:14 -0600251
252 # 3rd-lib
253 "log_viewer",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254)
255
256
257INTERNAL_IPS = ['127.0.0.1', '192.168.2.28']
258
259# Load django-fresh is TOASTER_DEVEL is set, and the module is available
260FRESH_ENABLED = False
261if os.environ.get('TOASTER_DEVEL', None) is not None:
262 try:
263 import fresh
Andrew Geissler82c905d2020-04-13 13:39:40 -0500264 MIDDLEWARE = ["fresh.middleware.FreshMiddleware",] + MIDDLEWARE
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265 INSTALLED_APPS = INSTALLED_APPS + ('fresh',)
266 FRESH_ENABLED = True
267 except:
268 pass
269
270DEBUG_PANEL_ENABLED = False
271if os.environ.get('TOASTER_DEVEL', None) is not None:
272 try:
273 import debug_toolbar, debug_panel
Andrew Geissler82c905d2020-04-13 13:39:40 -0500274 MIDDLEWARE = ['debug_panel.middleware.DebugPanelMiddleware',] + MIDDLEWARE
275 #MIDDLEWARE = MIDDLEWARE + ['debug_toolbar.middleware.DebugToolbarMiddleware',]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276 INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',)
277 DEBUG_PANEL_ENABLED = True
278
279 # this cache backend will be used by django-debug-panel
280 CACHES['debug-panel'] = {
281 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
282 'LOCATION': '/var/tmp/debug-panel-cache',
283 'TIMEOUT': 300,
284 'OPTIONS': {
285 'MAX_ENTRIES': 200
286 }
287 }
288
289 except:
290 pass
291
292
293SOUTH_TESTS_MIGRATE = False
294
295
296# We automatically detect and install applications here if
297# they have a 'models.py' or 'views.py' file
298import os
299currentdir = os.path.dirname(__file__)
300for t in os.walk(os.path.dirname(currentdir)):
301 modulename = os.path.basename(t[0])
302 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600303 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304 continue
305
306 if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS:
307 INSTALLED_APPS = INSTALLED_APPS + (modulename,)
308
309# A sample logging configuration. The only tangible logging
310# performed by this configuration is to send an email to
311# the site admins on every HTTP 500 error when DEBUG=False.
312# See http://docs.djangoproject.com/en/dev/topics/logging for
313# more details on how to customize your logging configuration.
Andrew Geissler20137392023-10-12 04:59:14 -0600314LOGGING = LOGGING_SETTINGS
315
316# Build paths inside the project like this: BASE_DIR / 'subdir'.
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600317BUILDDIR = os.environ.get("BUILDDIR", TMPDIR)
Andrew Geissler20137392023-10-12 04:59:14 -0600318
319# LOG VIEWER
320# https://pypi.org/project/django-log-viewer/
321LOG_VIEWER_FILES_PATTERN = '*.log*'
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600322LOG_VIEWER_FILES_DIR = os.path.join(BUILDDIR, "toaster_logs/")
Andrew Geissler20137392023-10-12 04:59:14 -0600323LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page
324LOG_VIEWER_MAX_READ_LINES = 100000 # total log lines will be read
325LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL']
326
327# Optionally you can set the next variables in order to customize the admin:
328LOG_VIEWER_FILE_LIST_TITLE = "Logs list"
329
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330if DEBUG and SQL_DEBUG:
331 LOGGING['loggers']['django.db.backends'] = {
332 'level': 'DEBUG',
333 'handlers': ['console'],
334 }
335
336
337# If we're using sqlite, we need to tweak the performance a bit
338from django.db.backends.signals import connection_created
339def activate_synchronous_off(sender, connection, **kwargs):
340 if connection.vendor == 'sqlite':
341 cursor = connection.cursor()
342 cursor.execute('PRAGMA synchronous = 0;')
343connection_created.connect(activate_synchronous_off)
344#
345