blob: b083cf5885b0b4ddd3fe9ed6109475473f447493 [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
111# If you set this to False, Django will not format dates, numbers and
112# calendars according to the current locale.
113USE_L10N = True
114
115# If you set this to False, Django will not use timezone-aware datetimes.
116USE_TZ = True
117
118# Absolute filesystem path to the directory that will hold user-uploaded files.
119# Example: "/var/www/example.com/media/"
120MEDIA_ROOT = ''
121
122# URL that handles the media served from MEDIA_ROOT. Make sure to use a
123# trailing slash.
124# Examples: "http://example.com/media/", "http://media.example.com/"
125MEDIA_URL = ''
126
127# Absolute path to the directory static files should be collected to.
128# Don't put anything in this directory yourself; store your static files
129# in apps' "static/" subdirectories and in STATICFILES_DIRS.
130# Example: "/var/www/example.com/static/"
131STATIC_ROOT = ''
132
133# URL prefix for static files.
134# Example: "http://example.com/static/", "http://static.example.com/"
135STATIC_URL = '/static/'
136
137# Additional locations of static files
138STATICFILES_DIRS = (
139 # Put strings here, like "/home/html/static" or "C:/www/django/static".
140 # Always use forward slashes, even on Windows.
141 # Don't forget to use absolute paths, not relative paths.
142)
143
144# List of finder classes that know how to find static files in
145# various locations.
146STATICFILES_FINDERS = (
147 'django.contrib.staticfiles.finders.FileSystemFinder',
148 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
149# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
150)
151
152# Make this unique, and don't share it with anybody.
153SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT'
154
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500155class InvalidString(str):
156 def __mod__(self, other):
157 from django.template.base import TemplateSyntaxError
158 raise TemplateSyntaxError(
159 "Undefined variable or unknown value for: \"%s\"" % other)
160
161TEMPLATES = [
162 {
163 'BACKEND': 'django.template.backends.django.DjangoTemplates',
164 'DIRS': [
165 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
166 # Always use forward slashes, even on Windows.
167 # Don't forget to use absolute paths, not relative paths.
168 ],
169 'OPTIONS': {
170 'context_processors': [
171 # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
172 # list if you haven't customized them:
173 'django.contrib.auth.context_processors.auth',
174 'django.template.context_processors.debug',
175 'django.template.context_processors.i18n',
176 'django.template.context_processors.media',
177 'django.template.context_processors.static',
178 'django.template.context_processors.tz',
179 'django.contrib.messages.context_processors.messages',
180 # Custom
181 'django.template.context_processors.request',
182 'toastergui.views.managedcontextprocessor',
183
184 ],
185 'loaders': [
186 # List of callables that know how to import templates from various sources.
187 'django.template.loaders.filesystem.Loader',
188 'django.template.loaders.app_directories.Loader',
189 #'django.template.loaders.eggs.Loader',
190 ],
Andrew Geissler20137392023-10-12 04:59:14 -0600191 # https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled
192 # Generally, string_if_invalid should only be enabled in order to debug
193 # a specific template problem, then cleared once debugging is complete.
194 # If you assign a value other than '' to string_if_invalid,
195 # you will experience rendering problems with these templates and sites.
196 # 'string_if_invalid': InvalidString("%s"),
197 'string_if_invalid': "",
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500198 'debug': DEBUG,
199 },
200 },
201]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202
Andrew Geissler82c905d2020-04-13 13:39:40 -0500203MIDDLEWARE = [
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204 'django.middleware.common.CommonMiddleware',
205 'django.contrib.sessions.middleware.SessionMiddleware',
206 'django.middleware.csrf.CsrfViewMiddleware',
207 'django.contrib.auth.middleware.AuthenticationMiddleware',
208 'django.contrib.messages.middleware.MessageMiddleware',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500209 'django.contrib.auth.middleware.AuthenticationMiddleware',
210 'django.contrib.messages.middleware.MessageMiddleware',
211 'django.contrib.sessions.middleware.SessionMiddleware',
212]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500213
214CACHES = {
215 # 'default': {
216 # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
217 # 'LOCATION': '127.0.0.1:11211',
218 # },
219 'default': {
220 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500221 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 'TIMEOUT': 1,
223 }
224 }
225
226
227from os.path import dirname as DN
228SITE_ROOT=DN(DN(os.path.abspath(__file__)))
229
230import subprocess
231TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
232TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
233
234ROOT_URLCONF = 'toastermain.urls'
235
236# Python dotted path to the WSGI application used by Django's runserver.
237WSGI_APPLICATION = 'toastermain.wsgi.application'
238
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239
240INSTALLED_APPS = (
241 'django.contrib.auth',
242 'django.contrib.contenttypes',
243 'django.contrib.messages',
244 'django.contrib.sessions',
245 'django.contrib.admin',
246 'django.contrib.staticfiles',
247
248 # Uncomment the next line to enable admin documentation:
249 # 'django.contrib.admindocs',
250 'django.contrib.humanize',
251 'bldcollector',
252 'toastermain',
Andrew Geissler20137392023-10-12 04:59:14 -0600253
254 # 3rd-lib
255 "log_viewer",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256)
257
258
259INTERNAL_IPS = ['127.0.0.1', '192.168.2.28']
260
261# Load django-fresh is TOASTER_DEVEL is set, and the module is available
262FRESH_ENABLED = False
263if os.environ.get('TOASTER_DEVEL', None) is not None:
264 try:
265 import fresh
Andrew Geissler82c905d2020-04-13 13:39:40 -0500266 MIDDLEWARE = ["fresh.middleware.FreshMiddleware",] + MIDDLEWARE
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267 INSTALLED_APPS = INSTALLED_APPS + ('fresh',)
268 FRESH_ENABLED = True
269 except:
270 pass
271
272DEBUG_PANEL_ENABLED = False
273if os.environ.get('TOASTER_DEVEL', None) is not None:
274 try:
275 import debug_toolbar, debug_panel
Andrew Geissler82c905d2020-04-13 13:39:40 -0500276 MIDDLEWARE = ['debug_panel.middleware.DebugPanelMiddleware',] + MIDDLEWARE
277 #MIDDLEWARE = MIDDLEWARE + ['debug_toolbar.middleware.DebugToolbarMiddleware',]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',)
279 DEBUG_PANEL_ENABLED = True
280
281 # this cache backend will be used by django-debug-panel
282 CACHES['debug-panel'] = {
283 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
284 'LOCATION': '/var/tmp/debug-panel-cache',
285 'TIMEOUT': 300,
286 'OPTIONS': {
287 'MAX_ENTRIES': 200
288 }
289 }
290
291 except:
292 pass
293
294
295SOUTH_TESTS_MIGRATE = False
296
297
298# We automatically detect and install applications here if
299# they have a 'models.py' or 'views.py' file
300import os
301currentdir = os.path.dirname(__file__)
302for t in os.walk(os.path.dirname(currentdir)):
303 modulename = os.path.basename(t[0])
304 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600305 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306 continue
307
308 if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS:
309 INSTALLED_APPS = INSTALLED_APPS + (modulename,)
310
311# A sample logging configuration. The only tangible logging
312# performed by this configuration is to send an email to
313# the site admins on every HTTP 500 error when DEBUG=False.
314# See http://docs.djangoproject.com/en/dev/topics/logging for
315# more details on how to customize your logging configuration.
Andrew Geissler20137392023-10-12 04:59:14 -0600316LOGGING = LOGGING_SETTINGS
317
318# Build paths inside the project like this: BASE_DIR / 'subdir'.
319BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
320
321# LOG VIEWER
322# https://pypi.org/project/django-log-viewer/
323LOG_VIEWER_FILES_PATTERN = '*.log*'
324LOG_VIEWER_FILES_DIR = os.path.join(BASE_DIR, 'logs')
325LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page
326LOG_VIEWER_MAX_READ_LINES = 100000 # total log lines will be read
327LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL']
328
329# Optionally you can set the next variables in order to customize the admin:
330LOG_VIEWER_FILE_LIST_TITLE = "Logs list"
331
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500332
333if DEBUG and SQL_DEBUG:
334 LOGGING['loggers']['django.db.backends'] = {
335 'level': 'DEBUG',
336 'handlers': ['console'],
337 }
338
339
340# If we're using sqlite, we need to tweak the performance a bit
341from django.db.backends.signals import connection_created
342def activate_synchronous_off(sender, connection, **kwargs):
343 if connection.vendor == 'sqlite':
344 cursor = connection.cursor()
345 cursor.execute('PRAGMA synchronous = 0;')
346connection_created.connect(activate_synchronous_off)
347#
348