Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # BitBake Toaster Implementation |
| 3 | # |
| 4 | # Copyright (C) 2013 Intel Corporation |
| 5 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | |
| 9 | # Django settings for Toaster project. |
| 10 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | import os |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | |
| 13 | DEBUG = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | |
| 15 | # Set to True to see the SQL queries in console |
| 16 | SQL_DEBUG = False |
| 17 | if os.environ.get("TOASTER_SQLDEBUG", None) is not None: |
| 18 | SQL_DEBUG = True |
| 19 | |
| 20 | |
| 21 | ADMINS = ( |
| 22 | # ('Your Name', 'your_email@example.com'), |
| 23 | ) |
| 24 | |
| 25 | MANAGERS = ADMINS |
| 26 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | TOASTER_SQLITE_DEFAULT_DIR = os.environ.get('TOASTER_DIR') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | DATABASES = { |
| 30 | 'default': { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 31 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | 'USER': '', |
| 36 | 'PASSWORD': '', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | #'HOST': '127.0.0.1', # e.g. mysql server |
| 38 | #'PORT': '3306', # e.g. mysql port |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 42 | # New in Django 3.2 |
| 43 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
| 44 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | # 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 |
| 48 | if 'sqlite' in DATABASES['default']['ENGINE']: |
| 49 | DATABASES['default']['OPTIONS'] = { 'timeout': 20 } |
| 50 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 51 | # 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. |
| 61 | if DEBUG is True: |
| 62 | # this will allow connection via localhost,hostname, or fqdn |
| 63 | ALLOWED_HOSTS = ['*'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | |
| 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 |
| 71 | import hashlib |
| 72 | if 'TZ' in os.environ: |
| 73 | TIME_ZONE = os.environ['TZ'] |
| 74 | else: |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | try: |
| 89 | if pytz.timezone(zonename) is not None: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 90 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename |
| 91 | except UnknownTimeZoneError as ValueError: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | # we expect timezone failures here, just move over |
| 93 | pass |
| 94 | except ImportError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 95 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 97 | TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | |
| 99 | # Language code for this installation. All choices can be found here: |
| 100 | # http://www.i18nguy.com/unicode/language-identifiers.html |
| 101 | LANGUAGE_CODE = 'en-us' |
| 102 | |
| 103 | SITE_ID = 1 |
| 104 | |
| 105 | # If you set this to False, Django will make some optimizations so as not |
| 106 | # to load the internationalization machinery. |
| 107 | USE_I18N = True |
| 108 | |
| 109 | # If you set this to False, Django will not format dates, numbers and |
| 110 | # calendars according to the current locale. |
| 111 | USE_L10N = True |
| 112 | |
| 113 | # If you set this to False, Django will not use timezone-aware datetimes. |
| 114 | USE_TZ = True |
| 115 | |
| 116 | # Absolute filesystem path to the directory that will hold user-uploaded files. |
| 117 | # Example: "/var/www/example.com/media/" |
| 118 | MEDIA_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/" |
| 123 | MEDIA_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/" |
| 129 | STATIC_ROOT = '' |
| 130 | |
| 131 | # URL prefix for static files. |
| 132 | # Example: "http://example.com/static/", "http://static.example.com/" |
| 133 | STATIC_URL = '/static/' |
| 134 | |
| 135 | # Additional locations of static files |
| 136 | STATICFILES_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. |
| 144 | STATICFILES_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. |
| 151 | SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT' |
| 152 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 153 | class 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 | |
| 159 | TEMPLATES = [ |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 194 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 195 | MIDDLEWARE = [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | '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 Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 201 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 202 | 'django.contrib.messages.middleware.MessageMiddleware', |
| 203 | 'django.contrib.sessions.middleware.SessionMiddleware', |
| 204 | ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | |
| 206 | CACHES = { |
| 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 213 | 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | 'TIMEOUT': 1, |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | from os.path import dirname as DN |
| 220 | SITE_ROOT=DN(DN(os.path.abspath(__file__))) |
| 221 | |
| 222 | import subprocess |
| 223 | TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 224 | TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 225 | |
| 226 | ROOT_URLCONF = 'toastermain.urls' |
| 227 | |
| 228 | # Python dotted path to the WSGI application used by Django's runserver. |
| 229 | WSGI_APPLICATION = 'toastermain.wsgi.application' |
| 230 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | |
| 232 | INSTALLED_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | ) |
| 246 | |
| 247 | |
| 248 | INTERNAL_IPS = ['127.0.0.1', '192.168.2.28'] |
| 249 | |
| 250 | # Load django-fresh is TOASTER_DEVEL is set, and the module is available |
| 251 | FRESH_ENABLED = False |
| 252 | if os.environ.get('TOASTER_DEVEL', None) is not None: |
| 253 | try: |
| 254 | import fresh |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 255 | MIDDLEWARE = ["fresh.middleware.FreshMiddleware",] + MIDDLEWARE |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 256 | INSTALLED_APPS = INSTALLED_APPS + ('fresh',) |
| 257 | FRESH_ENABLED = True |
| 258 | except: |
| 259 | pass |
| 260 | |
| 261 | DEBUG_PANEL_ENABLED = False |
| 262 | if os.environ.get('TOASTER_DEVEL', None) is not None: |
| 263 | try: |
| 264 | import debug_toolbar, debug_panel |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 265 | MIDDLEWARE = ['debug_panel.middleware.DebugPanelMiddleware',] + MIDDLEWARE |
| 266 | #MIDDLEWARE = MIDDLEWARE + ['debug_toolbar.middleware.DebugToolbarMiddleware',] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | 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 | |
| 284 | SOUTH_TESTS_MIGRATE = False |
| 285 | |
| 286 | |
| 287 | # We automatically detect and install applications here if |
| 288 | # they have a 'models.py' or 'views.py' file |
| 289 | import os |
| 290 | currentdir = os.path.dirname(__file__) |
| 291 | for 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 294 | if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | 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. |
| 305 | LOGGING = { |
| 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 | |
| 343 | if 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 |
| 351 | from django.db.backends.signals import connection_created |
| 352 | def activate_synchronous_off(sender, connection, **kwargs): |
| 353 | if connection.vendor == 'sqlite': |
| 354 | cursor = connection.cursor() |
| 355 | cursor.execute('PRAGMA synchronous = 0;') |
| 356 | connection_created.connect(activate_synchronous_off) |
| 357 | # |
| 358 | |