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 | |
| 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 |
| 45 | if 'sqlite' in DATABASES['default']['ENGINE']: |
| 46 | DATABASES['default']['OPTIONS'] = { 'timeout': 20 } |
| 47 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 48 | # 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. |
| 58 | if DEBUG is True: |
| 59 | # this will allow connection via localhost,hostname, or fqdn |
| 60 | ALLOWED_HOSTS = ['*'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | |
| 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 |
| 68 | import hashlib |
| 69 | if 'TZ' in os.environ: |
| 70 | TIME_ZONE = os.environ['TZ'] |
| 71 | else: |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | try: |
| 86 | if pytz.timezone(zonename) is not None: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 87 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename |
| 88 | except UnknownTimeZoneError as ValueError: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | # we expect timezone failures here, just move over |
| 90 | pass |
| 91 | except ImportError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 92 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 93 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 94 | TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | |
| 96 | # Language code for this installation. All choices can be found here: |
| 97 | # http://www.i18nguy.com/unicode/language-identifiers.html |
| 98 | LANGUAGE_CODE = 'en-us' |
| 99 | |
| 100 | SITE_ID = 1 |
| 101 | |
| 102 | # If you set this to False, Django will make some optimizations so as not |
| 103 | # to load the internationalization machinery. |
| 104 | USE_I18N = True |
| 105 | |
| 106 | # If you set this to False, Django will not format dates, numbers and |
| 107 | # calendars according to the current locale. |
| 108 | USE_L10N = True |
| 109 | |
| 110 | # If you set this to False, Django will not use timezone-aware datetimes. |
| 111 | USE_TZ = True |
| 112 | |
| 113 | # Absolute filesystem path to the directory that will hold user-uploaded files. |
| 114 | # Example: "/var/www/example.com/media/" |
| 115 | MEDIA_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/" |
| 120 | MEDIA_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/" |
| 126 | STATIC_ROOT = '' |
| 127 | |
| 128 | # URL prefix for static files. |
| 129 | # Example: "http://example.com/static/", "http://static.example.com/" |
| 130 | STATIC_URL = '/static/' |
| 131 | |
| 132 | # Additional locations of static files |
| 133 | STATICFILES_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. |
| 141 | STATICFILES_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. |
| 148 | SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT' |
| 149 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 150 | class 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 | |
| 156 | TEMPLATES = [ |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 192 | MIDDLEWARE = [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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', |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 198 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 199 | 'django.contrib.messages.middleware.MessageMiddleware', |
| 200 | 'django.contrib.sessions.middleware.SessionMiddleware', |
| 201 | ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | |
| 203 | CACHES = { |
| 204 | # 'default': { |
| 205 | # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', |
| 206 | # 'LOCATION': '127.0.0.1:11211', |
| 207 | # }, |
| 208 | 'default': { |
| 209 | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 210 | 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | 'TIMEOUT': 1, |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | |
| 216 | from os.path import dirname as DN |
| 217 | SITE_ROOT=DN(DN(os.path.abspath(__file__))) |
| 218 | |
| 219 | import subprocess |
| 220 | TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 221 | TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 222 | |
| 223 | ROOT_URLCONF = 'toastermain.urls' |
| 224 | |
| 225 | # Python dotted path to the WSGI application used by Django's runserver. |
| 226 | WSGI_APPLICATION = 'toastermain.wsgi.application' |
| 227 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | |
| 229 | INSTALLED_APPS = ( |
| 230 | 'django.contrib.auth', |
| 231 | 'django.contrib.contenttypes', |
| 232 | 'django.contrib.messages', |
| 233 | 'django.contrib.sessions', |
| 234 | 'django.contrib.admin', |
| 235 | 'django.contrib.staticfiles', |
| 236 | |
| 237 | # Uncomment the next line to enable admin documentation: |
| 238 | # 'django.contrib.admindocs', |
| 239 | 'django.contrib.humanize', |
| 240 | 'bldcollector', |
| 241 | 'toastermain', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 242 | ) |
| 243 | |
| 244 | |
| 245 | INTERNAL_IPS = ['127.0.0.1', '192.168.2.28'] |
| 246 | |
| 247 | # Load django-fresh is TOASTER_DEVEL is set, and the module is available |
| 248 | FRESH_ENABLED = False |
| 249 | if os.environ.get('TOASTER_DEVEL', None) is not None: |
| 250 | try: |
| 251 | import fresh |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 252 | MIDDLEWARE = ["fresh.middleware.FreshMiddleware",] + MIDDLEWARE |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 253 | INSTALLED_APPS = INSTALLED_APPS + ('fresh',) |
| 254 | FRESH_ENABLED = True |
| 255 | except: |
| 256 | pass |
| 257 | |
| 258 | DEBUG_PANEL_ENABLED = False |
| 259 | if os.environ.get('TOASTER_DEVEL', None) is not None: |
| 260 | try: |
| 261 | import debug_toolbar, debug_panel |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 262 | MIDDLEWARE = ['debug_panel.middleware.DebugPanelMiddleware',] + MIDDLEWARE |
| 263 | #MIDDLEWARE = MIDDLEWARE + ['debug_toolbar.middleware.DebugToolbarMiddleware',] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',) |
| 265 | DEBUG_PANEL_ENABLED = True |
| 266 | |
| 267 | # this cache backend will be used by django-debug-panel |
| 268 | CACHES['debug-panel'] = { |
| 269 | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
| 270 | 'LOCATION': '/var/tmp/debug-panel-cache', |
| 271 | 'TIMEOUT': 300, |
| 272 | 'OPTIONS': { |
| 273 | 'MAX_ENTRIES': 200 |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | except: |
| 278 | pass |
| 279 | |
| 280 | |
| 281 | SOUTH_TESTS_MIGRATE = False |
| 282 | |
| 283 | |
| 284 | # We automatically detect and install applications here if |
| 285 | # they have a 'models.py' or 'views.py' file |
| 286 | import os |
| 287 | currentdir = os.path.dirname(__file__) |
| 288 | for t in os.walk(os.path.dirname(currentdir)): |
| 289 | modulename = os.path.basename(t[0]) |
| 290 | #if we have a virtualenv skip it to avoid incorrect imports |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | 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] | 292 | continue |
| 293 | |
| 294 | if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS: |
| 295 | INSTALLED_APPS = INSTALLED_APPS + (modulename,) |
| 296 | |
| 297 | # A sample logging configuration. The only tangible logging |
| 298 | # performed by this configuration is to send an email to |
| 299 | # the site admins on every HTTP 500 error when DEBUG=False. |
| 300 | # See http://docs.djangoproject.com/en/dev/topics/logging for |
| 301 | # more details on how to customize your logging configuration. |
| 302 | LOGGING = { |
| 303 | 'version': 1, |
| 304 | 'disable_existing_loggers': False, |
| 305 | 'filters': { |
| 306 | 'require_debug_false': { |
| 307 | '()': 'django.utils.log.RequireDebugFalse' |
| 308 | } |
| 309 | }, |
| 310 | 'formatters': { |
| 311 | 'datetime': { |
| 312 | 'format': '%(asctime)s %(levelname)s %(message)s' |
| 313 | } |
| 314 | }, |
| 315 | 'handlers': { |
| 316 | 'mail_admins': { |
| 317 | 'level': 'ERROR', |
| 318 | 'filters': ['require_debug_false'], |
| 319 | 'class': 'django.utils.log.AdminEmailHandler' |
| 320 | }, |
| 321 | 'console': { |
| 322 | 'level': 'DEBUG', |
| 323 | 'class': 'logging.StreamHandler', |
| 324 | 'formatter': 'datetime', |
| 325 | } |
| 326 | }, |
| 327 | 'loggers': { |
| 328 | 'toaster' : { |
| 329 | 'handlers': ['console'], |
| 330 | 'level': 'DEBUG', |
| 331 | }, |
| 332 | 'django.request': { |
| 333 | 'handlers': ['console'], |
| 334 | 'level': 'WARN', |
| 335 | 'propagate': True, |
| 336 | }, |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if DEBUG and SQL_DEBUG: |
| 341 | LOGGING['loggers']['django.db.backends'] = { |
| 342 | 'level': 'DEBUG', |
| 343 | 'handlers': ['console'], |
| 344 | } |
| 345 | |
| 346 | |
| 347 | # If we're using sqlite, we need to tweak the performance a bit |
| 348 | from django.db.backends.signals import connection_created |
| 349 | def activate_synchronous_off(sender, connection, **kwargs): |
| 350 | if connection.vendor == 'sqlite': |
| 351 | cursor = connection.cursor() |
| 352 | cursor.execute('PRAGMA synchronous = 0;') |
| 353 | connection_created.connect(activate_synchronous_off) |
| 354 | # |
| 355 | |