blob: 74501fa26bb311cd82a6e5ad13f4e66484555cfd [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
192MIDDLEWARE_CLASSES = (
193 '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',
198 # Uncomment the next line for simple clickjacking protection:
199 # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
200)
201
202CACHES = {
203 # 'default': {
204 # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
205 # 'LOCATION': '127.0.0.1:11211',
206 # },
207 'default': {
208 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500209 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210 'TIMEOUT': 1,
211 }
212 }
213
214
215from os.path import dirname as DN
216SITE_ROOT=DN(DN(os.path.abspath(__file__)))
217
218import subprocess
219TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
220TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
221
222ROOT_URLCONF = 'toastermain.urls'
223
224# Python dotted path to the WSGI application used by Django's runserver.
225WSGI_APPLICATION = 'toastermain.wsgi.application'
226
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227
228INSTALLED_APPS = (
229 'django.contrib.auth',
230 'django.contrib.contenttypes',
231 'django.contrib.messages',
232 'django.contrib.sessions',
233 'django.contrib.admin',
234 'django.contrib.staticfiles',
235
236 # Uncomment the next line to enable admin documentation:
237 # 'django.contrib.admindocs',
238 'django.contrib.humanize',
239 'bldcollector',
240 'toastermain',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241)
242
243
244INTERNAL_IPS = ['127.0.0.1', '192.168.2.28']
245
246# Load django-fresh is TOASTER_DEVEL is set, and the module is available
247FRESH_ENABLED = False
248if os.environ.get('TOASTER_DEVEL', None) is not None:
249 try:
250 import fresh
251 MIDDLEWARE_CLASSES = ("fresh.middleware.FreshMiddleware",) + MIDDLEWARE_CLASSES
252 INSTALLED_APPS = INSTALLED_APPS + ('fresh',)
253 FRESH_ENABLED = True
254 except:
255 pass
256
257DEBUG_PANEL_ENABLED = False
258if os.environ.get('TOASTER_DEVEL', None) is not None:
259 try:
260 import debug_toolbar, debug_panel
261 MIDDLEWARE_CLASSES = ('debug_panel.middleware.DebugPanelMiddleware',) + MIDDLEWARE_CLASSES
262 #MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',)
263 INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',)
264 DEBUG_PANEL_ENABLED = True
265
266 # this cache backend will be used by django-debug-panel
267 CACHES['debug-panel'] = {
268 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
269 'LOCATION': '/var/tmp/debug-panel-cache',
270 'TIMEOUT': 300,
271 'OPTIONS': {
272 'MAX_ENTRIES': 200
273 }
274 }
275
276 except:
277 pass
278
279
280SOUTH_TESTS_MIGRATE = False
281
282
283# We automatically detect and install applications here if
284# they have a 'models.py' or 'views.py' file
285import os
286currentdir = os.path.dirname(__file__)
287for t in os.walk(os.path.dirname(currentdir)):
288 modulename = os.path.basename(t[0])
289 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600290 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291 continue
292
293 if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS:
294 INSTALLED_APPS = INSTALLED_APPS + (modulename,)
295
296# A sample logging configuration. The only tangible logging
297# performed by this configuration is to send an email to
298# the site admins on every HTTP 500 error when DEBUG=False.
299# See http://docs.djangoproject.com/en/dev/topics/logging for
300# more details on how to customize your logging configuration.
301LOGGING = {
302 'version': 1,
303 'disable_existing_loggers': False,
304 'filters': {
305 'require_debug_false': {
306 '()': 'django.utils.log.RequireDebugFalse'
307 }
308 },
309 'formatters': {
310 'datetime': {
311 'format': '%(asctime)s %(levelname)s %(message)s'
312 }
313 },
314 'handlers': {
315 'mail_admins': {
316 'level': 'ERROR',
317 'filters': ['require_debug_false'],
318 'class': 'django.utils.log.AdminEmailHandler'
319 },
320 'console': {
321 'level': 'DEBUG',
322 'class': 'logging.StreamHandler',
323 'formatter': 'datetime',
324 }
325 },
326 'loggers': {
327 'toaster' : {
328 'handlers': ['console'],
329 'level': 'DEBUG',
330 },
331 'django.request': {
332 'handlers': ['console'],
333 'level': 'WARN',
334 'propagate': True,
335 },
336 }
337}
338
339if DEBUG and SQL_DEBUG:
340 LOGGING['loggers']['django.db.backends'] = {
341 'level': 'DEBUG',
342 'handlers': ['console'],
343 }
344
345
346# If we're using sqlite, we need to tweak the performance a bit
347from django.db.backends.signals import connection_created
348def activate_synchronous_off(sender, connection, **kwargs):
349 if connection.vendor == 'sqlite':
350 cursor = connection.cursor()
351 cursor.execute('PRAGMA synchronous = 0;')
352connection_created.connect(activate_synchronous_off)
353#
354
355
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356